Estimated time: 15 minutesPrerequisites:Twilio Account Cloudinary AccountThinged.io Account ThingRaspberry Pi RPi CameraThis tutorial will step you through creating a thinged.io part that can take a photo with your Raspberry Pi, upload it to cloudinary and send it via mms using Twilio.
Well guide you through creating your first thinged part and how to think about structuring them, so you can build your own extensions to the Thinged.io platform.0: Setup your Raspberry Pi with Thinged.
ioSee your Raspberry Pi to take a photoUpload the photo to CloudinarySend a MMS using TwilioWrap upCreate the required accounts and get all the API keys and tokensOnce you create your Twilio and Cloudinary accounts, you can get your Account Ids and Access Tokens from their respective dashboards:2. Setup your Raspberry Pi with the Python Prequisites:Now you have your accounts created, we have to install requirements on the Raspberry Pi for communicating with Cloudinary and Twilio. sudo apt-get install python3-pippip3 install --user cloudinarypip3 install --user twilioDone.
2. Configure your Raspberry Pi cameraEnable your Raspberry Pis camera module through the raspi-config:sudo raspi-configSelect Interfacing Options , then Camera and enable it.Reboot your Raspberry Pi.
Test your camera:raspistill -v -o test.jpg3. Test the script on your Raspberry PiWeve created a github gist that you can use for taking these photos.
Download this script onto your Raspberry Pi and edit the following variables:cloudinary_cloud_namecloudinary_api_keycloudinary_api_secrettwilio_account_sidtwilio_auth_tokentwilio_from_numberphone_numberThe script itself is ultra simple and is comprised of a couple small functions:take_photo(photo_name) which takes the photo from the raspberry pi using the raspistill library installed in Raspbian by default.upload_photo_to_cloudinary(photo_file_name) which uploads a photo with the given name.send_mms(to, message, media_url) which sends a your photo using Twilio.
4. Creating the Thinged. io PartJust as the python script was a thin wrapper around the Cloudinary and Twilio, Thinged is a thin wrapper around shell commands.
A Thing is comprised of Parts which are just state that can be get and set through command line commands. The returned text of the command forms the basis of get parts and placeholders are used to step in for arguments in set commands. The Part we are creating looks like the following:There is a lot of different keys there, but dont worry- it is actually pretty simple.
Ive broken down the parameters below:humanName human friendly name that you can use to identify the part.description human friendly description so you can figure out how it works and add any other details. partId randomly generated string that thinged.
io uses to identify the part, and you use in the API to set values on it.type Either input, output or inputOutput defines whether the part is used to get state from your thing, set state on your thing, or a combination of the two (you can set it, but it could change elsewhere and should be read). Inputs require getCommand , outputs require setCommand.
setCommand The command that will be launched when setting a value. Here it just points to our python script. Addingvalue to this will be replaced everywhere with the parts value when you set commands via the API.
The python script will have to be loaded into the raspberry pi through other means.valueType This can be number, string or state. As mentioned earlier, Thinged is essentially a thin wrapper for command line commands, and so everything is translated into strings on the command line.
valueType is important for any GUI that wants to present details about the state of a part. Here, the valueType is state which implies that there are a discrete number of state, and they can be enumerated into values. This allows the GUI to present a nice button for 2 state parts and a drop down for 3 or more state parts.
states Each state represents a different discrete possibility. As Thinged.io will only trigger a set when a value changes, here the discrete states are duplicates of each other, but with different values.
regexes Useful for input or inputOutput parts where you would like to preprocess the response of the command.Create this part, either through the web portal, or through the API. from there you can add the part to your thinged and now you are done!
Wrap Up:If youve created the part, it should now look like this on the GUI:If you have loaded the script into your pi, and thinged. io service is running, everything is done. Now for the pay off: Press the button!
In this tutorial weve gone through working with thinged.io output parts to create a spy camera with a raspberry pi, cloudinary and twilio accounts and a 42 lines of python holding it all together. Stay tuned for more tutorials on thinged.
io.
Shenzhen TigerWong Technology Co.,Ltd
Tel: +86 13717037584
E-Mail: info@sztigerwong.com
Add: 1st Floor, Building A2, Silicon Valley Power Digital Industrial Park, No. 22 Dafu Road, Guanlan Street, Longhua District,
Shenzhen,GuangDong Province,China