Save 37% off PRO during our Black Friday Sale! »

IoT Cloud Platform: ThingSpeak

IoT Cloud Platform: ThingSpeak

1b0af2793f33bc86768fe97a9443c176?s=128

stwn

June 11, 2021
Tweet

Transcript

  1. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 1 Iwan

    Setiawan <stwn at unsoed.ac.id> IoT Cloud Platform: ThingSpeak
  2. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 2 Iwan

    Setiawan <stwn at unsoed.ac.id> Previous Week’s Material • Temperature monitoring – CPU w/ GPIO Zero – DHT11 w/ Adafruit DHT • Writing data to a CSV file • Displaying the data to a live graph with matplotlib • Actions: LED and buzzer Analog signal Compute Storage Digital signal Stallings, 2016 1 2 CSV +Humidity * https://components101.com/sensors/dht11-temperature-sensor DHT11* 3
  3. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 3 Iwan

    Setiawan <stwn at unsoed.ac.id> Previous Week’s Material • Temperature monitoring – CPU w/ GPIO Zero – DHT11 w/ Adafruit DHT • Writing data to a CSV file • Displaying the data to a live graph with matplotlib • Actions: LED and buzzer Analog signal Compute Storage Digital signal Stallings, 2016 Communications +Humidity 1 2 3 5 6 CSV +Notification Simple * https://components101.com/sensors/dht11-temperature-sensor DHT11*
  4. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 4 Iwan

    Setiawan <stwn at unsoed.ac.id> Previous Week’s Material • Temperature monitoring – CPU w/ GPIO Zero – DHT11 w/ Adafruit DHT • Writing data to a CSV file • Displaying the data to a live graph with matplotlib • Actions: LED and buzzer Analog signal Compute Storage Digital signal Stallings, 2016 Communications +Humidity 1 2 5 6 +Notification Cloud Compute Storage Simple * https://components101.com/sensors/dht11-temperature-sensor DHT11* 3 CSV
  5. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 5 Iwan

    Setiawan <stwn at unsoed.ac.id> Objectives • Learn how to setup channels on an IoT platform • Learn how to send collected data from an IoT device to the channel • Learn how to display the data on a dashboard
  6. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 6 Iwan

    Setiawan <stwn at unsoed.ac.id> Contents • Setting up a channel on ThingSpeak • Getting temperature and humidity data from DHT11 and sending the data to the channel • Displaying the data using a dashboard using Private and Public Views
  7. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 7 Iwan

    Setiawan <stwn at unsoed.ac.id> Cloud Computing Stallings, 2016
  8. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 8 Iwan

    Setiawan <stwn at unsoed.ac.id> Cloud Computing Stallings, 2016
  9. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 9 Iwan

    Setiawan <stwn at unsoed.ac.id> IoT Cloud Platforms Cloud IoT Core IoT Azure IoT Losant ThingsBoard
  10. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 10 Iwan

    Setiawan <stwn at unsoed.ac.id> IoT Cloud Platform • Data storing or aggregation – Live data streams via APIs – Time series database • Data visualization • Analytics • Apps – Transforming and/or visualizing data – Triggering actions
  11. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 11 Iwan

    Setiawan <stwn at unsoed.ac.id> Preparation • Raspberry Pi 4 set +Ethernet cable • Breadboard • Jumper wires • DHT11 sensor • MathWorks account Internet connection
  12. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 12 Iwan

    Setiawan <stwn at unsoed.ac.id> Creating an Account
  13. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 13 Iwan

    Setiawan <stwn at unsoed.ac.id> License Types
  14. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 14 Iwan

    Setiawan <stwn at unsoed.ac.id> Creating a Channel • Login, and click My Channels – New Channel • Set the channel settings – Name: ACNT-X Monitoring, e.g. ACNT-10 Monitoring – Description: Temperature and humidity monitoring – Field 1: Temperature – Field 2: Humidity • Click Save Channel Channel ID
  15. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 15 Iwan

    Setiawan <stwn at unsoed.ac.id> Protocols for IoT • REST API over HTTPS • MQTT – Considered lighweight – Publish-subscribe method
  16. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 16 Iwan

    Setiawan <stwn at unsoed.ac.id> API Keys and Write/Read URLs • Click to API Keys tab • Take notes – Write API Key to write data to a channel (WAPIK) – Read API Key to read data from a channel (RAPIK) – API Requests: Write Feeds https://api.thingspeak.com/update?api_key=WAPIK&field1=A&field2=B – API Requests: Read Feeds https://api.thingspeak.com/channels/[Channel ID]/feeds.json?api_key=RAPIK&results=2 Temperature data Humidity data
  17. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 17 Iwan

    Setiawan <stwn at unsoed.ac.id> Python Libraries • Adafruit DHT, a library for DHT11/DHT22 • urllib.request, a library for opening URLs * https://docs.python.org/3/library/urllib.request.html
  18. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 18 Iwan

    Setiawan <stwn at unsoed.ac.id> Code (1) • Type the code, save, and run import Adafruit_DHT as dht import urllib.request import csv sensor = dht.DHT11 pin = 21 CHAN_ID = Y0URCH4N1D API_WKEY = "Y0UR4P1WK3Y" # Change to your actual Write API Key API_WREQ = "https://api.thingspeak.com/update?api_key=" # Write API Key API_RKEY = “Y0UR4P1RK3Y” API_RREQ = "https://api.thingspeak.com/channels/{0}/feeds.json?".format(CHAN_ID) CSV_FILE = "/home/pi/acnt/iot-c2d.csv" [...] iot-d2c.py
  19. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 19 Iwan

    Setiawan <stwn at unsoed.ac.id> Code (2) [...] def sensor_read(): humi, temp = dht.read_retry(sensor, pin) if humi is not None and temp is not None: print("Temperature: {0:0.1f}*C Humidity: {1:0.1f}%".format(temp, humi)) else: print("Cannot read data from the sensor") return humi, temp def cloud_send(): send_req = urllib.request.urlopen(API_WREQ + '{0}&field1={1:0.1f}&field2={2:0.1f}'\ .format(API_WKEY, temp, humi)) [...] iot-d2c.py
  20. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 20 Iwan

    Setiawan <stwn at unsoed.ac.id> Code (3) [...] def cloud_receive(): receive_req = urllib.request.urlretrieve(API_RREQ + 'api_key={0}&results=2'\ .format(API_RKEY), CSV_FILE) with open(CSV_FILE) as file: csv_reader = csv.reader(file) for row in csv_reader: msg = row[2] if __name__ == "__main__": while True: try: humi, temp = sensor_read() cloud_send() cloud_receive() except KeyboardInterrupt: exit() iot-d2c.py
  21. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 21 Iwan

    Setiawan <stwn at unsoed.ac.id> Observation and Sharing • Observe the dashboard on Private View tab for 5 minutes and make sure that the channel on ThingSpeak received data from your IoT device • Click Sharing tab, select “Share channel view with everyone” • Click Public View tab and make sure that there is a dashboard with two charts shown
  22. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 22 Iwan

    Setiawan <stwn at unsoed.ac.id> IoT Assignment 4 • Simulate a scenario similar to Assignment 3 number 3. Please observe: – your dashboard for the sent data to the channel on ThingSpeak – CSV file output via read data from the channel • Continue to run data collecting and storing to the cloud for 12 2 hours • Optional: Send an email on heat alert, temperature > 35°C – Add Apps – MATLAB Analysis, or – Add Apps – React
  23. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 23 Iwan

    Setiawan <stwn at unsoed.ac.id> Results to be Uploaded 1. Experiment results: photos and explanations 2. Assignment 4 results – Attach you group’s Channel ID and CSV file – Photos and a demo video showing the results – Source code, screenshots/figures, and explanations Upload your experiment and assignment 4 results to Moodle • Using one PDF file • One group, one document • Upload your demo video somewhere, only attach the URL to the doc. 06/16 9pm code experiment
  24. Advanced Computer Networks Tutorials, Spring 2021, CSIE NTUST 24 Iwan

    Setiawan <stwn at unsoed.ac.id> Resources • Circuit Basics, “Logging Sensor Data to the Cloud Using the Raspberry Pi,” 2020. [Online]. Available: https://circuitbasics.com/logging-sensor-data-to-the- cloud-using-the-raspberry-pi/ • N. Vemu, “The Naivest Way to Send and Retrieve Data from Cloud (Using Python),” 2021. [Online]. Available: https://medium.com/geekculture/the-naivest-way-to- send-and-retrieve-data-from-cloud-using-python- 52a3e4b5fe24