Can't upload serially recieved data to thingspeak | Arduino | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
Can't upload serially recieved data to thingspeak
Avatar
shubham_ingle
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
1
November 20, 2016 - 12:41 pm
sp_Permalink sp_Print sp_EditHistory

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);

Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
2
November 20, 2016 - 7:38 pm
sp_Permalink sp_Print

Are you sure you are reading valid values from the serial port?  I wonder if you are sending blanks.

What happens if you add a 3rd constant value in your read loop to make sure you are sending at least one known value.

Eg

while (mySerial.available()>0)
  {
      int sensorValue = mySerial.read();
      ThingSpeak.setField(1,sensorValue);
      ThingSpeak.setField(2,mySerial.read());

      ThingSpeak.setField(3,10);
                                                                                 //   int myValue = sensorValue(sensorValue.toInt);
                                                                       // int sensorValue = 10;
       ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
       delay(15000);
       Serial.print("Sensor data=");
       delay(10);
       Serial.println(sensorValue);
 
 }

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
16 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

winnieeq69

AutoCheernpen

Bostermet

engladNed

iivenul

olewaeayafaku

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee