搜索
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.