hello guys...!
I'm trying to upload the serially received data from aurdino to esp8266 and display it on thingspeak. Data is available on serially(COM port) but not uploading to thingspeak would you please help me here's my code:
#ifdef SPARK
#include "ThingSpeak/ThingSpeak.h"
#else
#include "ThingSpeak.h"
#endif
#ifdef ARDUINO_ARCH_ESP8266
#include
#include
SoftwareSerial mySerial(9, 10); // RX, TX
char ssid[] = "myssid"; // your network SSID (name)
char pass[] = "mypasscode"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
#endif
unsigned long myChannelNumber = xxxxxx; //instead of x their is my channel no.
const char * myWriteAPIKey = "xxxxxxxxxxx"; //instead of x their is my write api key.
const int updateThingSpeakInterval = 20 * 1000; // 20 second interval at which to update ThingSpeak
//long lastConnectionTime = 0; // Variable Setup
//boolean lastConnected = false;
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, pass);
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
delay(500);
ThingSpeak.begin(client);// put your setup code here, to run once:
}
void loop() {
// float sensorValue;
while (mySerial.available()>0)
{
int sensorValue = mySerial.read();
ThingSpeak.setField(1,sensorValue);
ThingSpeak.setField(2,mySerial.read());
// int myValue = sensorValue(sensorValue.toInt);
// int sensorValue = 10;
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
delay(15000);
Serial.print("Sensor data=");
delay(10);
Serial.println(sensorValue);
}
//this code is to just verify data sending & it works promblem is with above loop...
float voltage= 0;
ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 2, voltage, myWriteAPIKey);
Serial.print("no_data");
delay(1000);
}