Your message line should now read as follows. Note that we need to convert the temperature from an integer / float into a string using the str() function. To the same line, add the current temperature stored in the “temperature” object. message = " IFTTT API KEY HERE?value1="ġ5. Remember to add your unique IFTTT API key. At the end of the URL add ?value1= and ensure that this is contained between quotation marks “ “. Create an object, message, to store the unique webhook URL that we created earlier. ![]() It should show the temperature each time the loop iterates. Print the temperature to the Python Shell (REPL). Save the current temperature to an object, temperature. We need to do this in order to get the raw data. Note that the code following this line is indented to show that it is part of the loop. A while True loop will continuously run the code until the Pico W is turned off. Add a loop to continually run the following code. This will either be True for a successful connection, or False if it was unable to connect. Print the current status of the Wi-Fi connection. This pause is present to allow a little extra leeway. This isn’t strictly necessary as the previous Wi-Fi connection is a blocking call that will either connect or fail, then release the block. Pause for five seconds before proceeding onward. Connect your Pico W to your Wi-Fi access point using its SSID and password. Create an object “wlan” and use it to connect the code to the Wi-Fi on the Raspberry Pi Pico W, then turn the Wi-Fi on. This object enables us to interact with the sensor connected on Pin 2, querying temperature data. Create an object, “sensor” which connects our code to the DHT11 connected via the GPIO. From the Machine module import Pin, this enables our code to interact with the GPIO. From the Time module, import the sleep function, we’ll use this to add a pause to the project. DHT refers to the DHT11 temperature sensor used in the project. Urequests is a version of requests, a means to work with web data, for MicroPython. Network enables the Pico W to connect to a Wi-Fi network. Follow this guide to download and install the MicroPython firmware, and setup Thonny.ģ. ![]() Our goal is now to install the latest MicroPython firmware release for our Raspberry Pi Pico W, then write a few lines of MicroPython code to connect to our Wi-Fi, take a temperature reading, and then send that data to IFTTT.ġ. IFTTT then sends the message to Twitter as per the applet we have just created. This is then sent to IFTTT using a custom webhook URL. It connects to our Wi-Fi, and every hour takes a temperature reading. Our Raspberry Pi Pico W is acting as a data collection device. You now have a valid webhook URL which will link your Raspberry Pi Pico W to Twitter via IFTTT. Your text will show a correct API key, for security reasons we have edited the text. Copy the Make a POST or GET web request link into notepad or a text editor. Visit this link in a new browser tab / window.Ģ. The URL requires our trigger (Post_Tweet) and an API key, unlocking IFTTT access.ġ. This URL is what sends the temperature data from the Raspberry Pi Pico W to our IFTTT service. The IFTTT Applet has been created, but we don’t yet have the webhook URL.
0 Comments
Leave a Reply. |