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

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





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

sp_Feed sp_TopicIcon
Can't upload serially recieved data to thingspeak
No permission to create posts
November 20, 2016
12:41 pm
Avatar
shubham_ingle
New Member
Members
Forum Posts: 1
Member Since:
November 19, 2016
sp_UserOfflineSmall Offline

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

November 20, 2016
7:38 pm
Avatar
rw950431

Top
Members
Forum Posts: 261
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

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:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

celinabw2, FitoSprayscroma, LunnonGor, lancevl16, bernicenk60, veronicadq18

Administrators: Hans: 387, lee: 457