Receiving data from Thingspeak to Pmod ESP32

andy neo on 3 Jun 2021 (Edited on 3 Jun 2021)
Latest activity Reply by Vinod on 3 Jun 2021

Hi,

I am currently having this internship which we are required to send sensor data to Thingspeak as well receiving data of '0' or '1' from Thingspeak to remotely control the LED.

We have done sending of sensor values to Thingspeak and I was able to send data of '0' and '1' ( on and off) to Thingspeak using a software called "Mendix". Our job is to control the LED from a mobile app and a web dashboard by pressing a button which sends the data to Thingspeak I have created. I am using REST call API to send data to thingspeak by using these 2 URLs: https://api.thingspeak.com/update?api_key=UHVD1PPGDS2X&field1=0 or https://api.thingspeak.com/update?api_key=UHVD1PPGDS&field1=1

This is the C++ code we used to send sensor values to Thingspeak:

void setWifiMode(void){ u8 tx[]="AT+CWMODE=3\r\n"; u32 num = strlen((char *) tx); xil_printf((char *) tx); ESP32_SendBuffer(&ESP32, tx, num); usleep(100); receiveData(3); }

void connectWifi(void){ u8 tx[] = "AT+CWJAP=\"eee-iot\",\"hWV4IOcKp0JX\"\r\n";

    u32 num = strlen((char *) tx);
    xil_printf((char *) tx);
    ESP32_SendBuffer(&ESP32, tx, num);
    usleep(100);
    receiveData(30);
}

void establishConnection(void){ u8 tx[] = "AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80\r\n"; u32 num = strlen((char *) tx); xil_printf((char *) tx); ESP32_SendBuffer(&ESP32, tx, num); receiveData(10); }

void cipsend(float temp, u16 co2, u8 light, float humidity){ u8 command[150]; u8 finalcmd[50]; //field1 Ph field2 Temp field3 co2 field4 humidity field5 light sprintf((char*)command, "GET http://api.thingspeak.com/update?api_key=CE8E8ZJNGZM8&field1=0&field2=%d.%02d&field3=%d&field4=%d.%02d&field5=%d\r\n" ,(int) temp_degc,((int) (temp_degc * 100)) % 100,co2,(int) hum_perrh,((int) (hum_perrh * 100)) % 100,light); u32 length = strlen((char*)command); sprintf((char*)finalcmd, "AT+CIPSEND=%d\r\n", (int)length); u32 cmdlength =strlen((char*)finalcmd); xil_printf("Length %d\r\n", length); xil_printf((char *)finalcmd); ESP32_SendBuffer(&ESP32, finalcmd, cmdlength); sleep(1); xil_printf((char *)command); ESP32_SendBuffer(&ESP32, command, length); receiveData(4); }

We are using a FPGA hardware called Zybo if that helps. I will really appreciate it if anyone could guide us on this as we are just students. My teammate is doing this alone while I am doing the mobile app and web dashboard alone as well and it is quite taxing for us to achieve this without any professional help.

Our difficulty right now is that we are unable to receive data '1' or '0' from Thingspeak to our FPGA hardware, Zybo. We are using Pmod ESP32 for wifi communication and we are currently using C++ language.

Vinod
Vinod on 3 Jun 2021 (Edited on 3 Jun 2021)

There are literally pages and pages of examples if you Google "ThingSpeak LED control". Here's a short video, many more of these are on YouTube .

andy neo
andy neo on 3 Jun 2021

Hi,

Yes we know. There are many examples of it using Arduino. However, as mentioned, we are not using Arduino for our project. We are using FPGA hardware called Zybo and the videos are not compatible with our hardware.

Vinod
Vinod on 3 Jun 2021

I believe the Zybo board has a ARM Cortex-A9 processor. The ThingSpeak library can be used to communicate from the ARM processor to ThingSpeak.

Christopher Stapels
Christopher Stapels on 3 Jun 2021

You have provided code to write the date to ThingSpeak, do you have code to read from ThingSpeak? I really suggest using the ThingSpeak Arduino library. Even if you don't use the examples directly, the code there will definitely help.

andy neo
andy neo on 3 Jun 2021

Hi,

According to my groupmate, he said that using the Thingspeak Arduino Library does not help. We are not using Arduino for our project. We are using a FPGA device called zybo. He also mentioned that both ESP32 and zybo do not support Thingspeak Arduino Library.

He said that there are 2 nodes for ESP 32, one mode is by using "AT command" and another mode "standalone mode" which utilizes a python server and Espressif, which is quite complicated for us to do.

Hence, we decided to use AT command to do the IOT remote control work. However, we have difficulty finding suitable resources that is able to support our zybo board as well. May we know what types of AT commands should be used for retrieving data from Thingspeak please?

Christopher Stapels
Christopher Stapels on 3 Jun 2021

There are examples for AT mode in the ThingSpeak library examples. You could use them for examples of how to construct the AT commands, even if you didnt use the library.

The standalone mode does not require python server and espressif. You can program the ESP32 using the Arduino IDE (standalone method), and then you could use the ThingSpeak library. (you wouldn't even have to use the AT commands) Unfortunately the ESP32 example in the doc doesn't use the library, but the ESP8266 examples are very similar, like this one , which does use the library. Also the examples that come with the library include a good one for ESP32, though you will have to modify it to add the communication with your Zybo.

I presume you are getting the data from the zybo to the ESP32 by a serial or spi or i2c interface. As soon as the data is received on the ESP32, you can trigger a callback that uses the ThingSpeak library functions to write to ThingSpeak. Or you can set a flag that says new data from Zybo and have a loop that look at that flag and then acts on the flag.