Hi there,
I am doing a project on underground cable fault detection.My prototype is ready, i am using an Arduino Uno as micro-controller.i need to send the data(fault locations) to an IoT platform. i have chosen ThngSpeak to upload my data.
I am able to send the data from the Arduino Uno to the WiFi module serially(checking the incoming data from the Uno on the serial monitor of the ESP8266-12E) and also i have been able to connect the WiFi module to ThingSpeak
The only problem is that only 0s are being sent to the platform even if the Arduino Uno is reading different values.Below is the code uploaded to the ESP8266-12E module. I an needing some help to figure out why the ESP8266-12E is not sending the data its reciving instead its sending only zeros
#include <ESP8266WiFi.h>
String apiKey = "GCC8OP2PI5JYIOY3";
const char* ssid = "Telecom-YCTb";
const char* password = "n4mcE5mV";
const char* server = "api.thingspeak.com";
int data1, data2, data3, data4, data5, ok;
WiFiClient client;
unsigned char buff[10], i;
String buffer1, buffer2;
void setup() {
Serial.begin(9600);
delay(10);
WiFi.begin(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
if (Serial.available() > 0)
{
delay(100);
while (Serial.available() > 0)
{
buffer1 = Serial.readString();
if (buffer1[0] == '*')
{
if (buffer1[7] == '#')
{
Serial.println(buffer1);
data1 = ((buffer1[1] - 0x30) * 10 + (buffer1[2] - 0x30));
data2 = ((buffer1[3] - 0x30) * 10 + (buffer1[4] - 0x30));
data3 = ((buffer1[5] - 0x30) * 10 + (buffer1[6] - 0x30));
}
}
}
}
if (client.connect(server, 80))
{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(data1);
postStr += "&field2=";
postStr += String(data2);
postStr += "&field3=";
postStr += String(data3);
postStr += "\r\n\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.println(postStr);
}
client.stop();
Serial.println("Waiting...");
delay(20000);
}