top of page

Integrating with ThingSpeak IoT Platform

To enable remote data access to the data, the project sends the data collected by Arduino to  ThingSpeak, through the ESP8276-NodeMCU module. This will make it possible for doctors/caregivers to view a patient's heart rate change through charts seen in ThingSpeak, and will also it possible to transmit data to the custom-designed Android app.

 

It is an  open-source IoT analytics Cloud Platform  and API to store and retrieve data using the HTTP protocol over the Internet or via a Local Area Network. ThingSpeak ‘Collects’ the data from the sensors, ‘Analyze and Visualize’ the data and ‘Acts’ by triggering a reaction.

               

Thanks to the visibility of charts, it is also easy to evaluate the progress of the patient, which can be accessed by both patients and doctors alike. It also serves to store a database with all patient history and allow devices such as mobile phones to access the data as well.

 

 The steps that have been conducted to connenct the ESP8266 module to ThingSpeak are the following:

​

Step 1: Sign up to ThingSpeak and create a new channel

​

Any MathWorks user can create an account in https://thingspeak.com/  .  The channel created is called “Heart Rate Monitorization System”, with channel ID 620080.   It is possible to add as many fields as desired, depending on the number of sensors. In this case there is a field for  the beats-per-minute (BPM), which will display the data received through the pulse rate sensor. And on the other hand, the field “Movement”, received from the accelerometer and that will indicate if the person is at rest (value = 0) or moving (value = 1).

​

​

​

​

​

It is assumed that the system may be used by more than one person. For simplification, it is assumed to be two, that is why there are two charts per person (even though the android app only uses one person). However additional charts can be included to monitorize more people.

​

​

​

​

​

​

​

​

​

​

​

​

​

​

Step 2: Channel sharing

​

 Another important aspect when dealing with medical records on the cloud is data privacy[9].  Because of that the ThingSpeak channel has been made private to restrict its view to the patient and doctors and/or nurses that are in charge of the patient.

​

​

​

​

​

​

​

​

​

​

​

Step 3: Getting  API keys

​

 In the section “API keys”,  the following 16-digit- API keys are saved, which allow to read/write the data collected.

​

​

​

​

​

​

​

​

​

​

Depending on the patient and the parameter to read, the “field” will differ.

  • Read API key: to allow people such as doctors, caregivers or the patients themselves, view the charts on ThingSpeak, and also to make it possible for the Android APP to retrieve the data.  Like this only the people that have this API will be able to access the medical data. The API request looks like this. In this case, the heart beat for patient 1 is retrieved as JSON data.

 

GET https://api.thingspeak.com/channels/620080/fields/1.json?api_key=5JV8F8O1J1FSMW7G&results=2

               

        To view the whole chart for field 1, the following URL can be used:

​

              https://api.thingspeak.com/channels/620080/charts/1?api_key=5JV8F8O1J1FSMW7G

 

  • Write API key:  used to write data to a channel. It is used by Arduino IDE, to send the data using the wifi module, as is later explained.  Here is an example to update the channel’s field1 (heart beat of patient 1).

 

                     GET https://api.thingspeak.com/update?api_key=NPHOWFAKQ1V4IH3B&field1=0

​

Step 4: Programing in Arduino IDE for data transmission

​

To enable data transmission to ThingSpeak using the NodeMCU it is necessary to add the following elements to Arduino IDE by going to “Board Manager”

  • ESP8266 board, by going to “Board Manager”

  • ThingSpeak

​

​

​

​

​

​

​

​

​

​

The first step is to establish a wifi connection to a valid router or hotspot. For that the network ssid and password are specified.

                Next, the ThingSpeak channel details are included, such as

  • Channel ID: 620080

  • Write API: NPHOWFAKQ1V4IH3B

  • pulseField: 1 (for patient 1)

  • accelerometerField: 2 (for patient 1)

 

​

​

​

​

​

​

The Arduino then reads both the pulse sensor and accelerometer data from the serial ports. Finally both pulse rate and accelerometer data are updated in their respective ThingSpeak fields through the Write API request.

​

​

​

​

This is equivalent to

​

GET https://api.thingspeak.com/update?api_key=NPHOWFAKQ1V4IH3B&field1=pulseValuefield2=accelerometerValue

​

The full code can be seen on the project's Github ( Arduino_NodeMCU_Write_Data_Channel.ino) 

It should be noted that as ThingSpeak only allows channel updating every 15 seconds, while sensor values are acquired real-time, not all of them are saved and transmitted to the Cloud. However it is assumed that a person's condition will not considerably change in that time interval. As within that time frame sensor data is accumulated,   only the last value of the sensors is retrieved.

​

Step 5: Final output

 

 The output for the heart rate sensor and movement detection can be seen in  two respective charts. The charts can be seen the following two ways:

  1. Introducing the following URL on the web browser:  https://api.thingspeak.com/channels/620080/charts/1?api_key=5JV8F8O1J1FSMW7G 

       https://api.thingspeak.com/channels/620080/charts/2?api_key=5JV8F8O1J1FSMW7G

     2.On the "Statistics" section of the pulse rate Android app (user must log in first). Only the pulse rate is seen here as is the most interesting for the user. For more information regarding the app refer to the "The App" section of the blog

​

​

​

​

​

​

​

​

​

​

​

t1.JPG
t2.png
t3.png
t4.png
t6.png
y7.png
thing1.JPG
thing2.JPG
bottom of page