Issues of updating the chart data, but the entry has been always updated | ThingSpeak API | 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
Issues of updating the chart data, but the entry has been always updated
Avatar
ryan528
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
1
January 24, 2018 - 1:54 pm
sp_Permalink sp_Print

 Hello Guys

I have a weird problem with transferring and updating chart data on Thingspeak. However, the entry was updated when the sensors captured new data. The channel is public https://thingspeak.com/channels/410378.

Here are the codes I have uploaded to the arduino uno board. Please help me out. It is really killing me, since I tried almost methods available online.

#include "MutichannelGasSensor.h"
#include <CytronWiFiClient.h>
#include <CytronWiFiServer.h>
#include <CytronWiFiShield.h>
#include <ThingSpeak.h>
#include <Wire.h>

// Network Parameters
const char* ssid = "LoveSalus";
const char* pass = "salus0411";

// ThingSpeak information
char thingSpeakAddress[] = "api.thingspeak.com";
unsigned long channelID = 410378;
char* writeAPIKey = "UBFR2PU51PN7ONJO";
char* readAPIKey = "NQJ7ZIAGVON0UQEV";
const unsigned long postingInterval = 120L * 1000L;

unsigned int dataFieldOne = 1; // Field to write NH3 data
unsigned int dataFieldTwo = 2; // Field to write CO data
unsigned int dataFieldThree = 3; // Field to write NO2 data
unsigned int dataFieldFour = 4; // Field to write C3H8 data

unsigned long lastConnectionTime = 0;
long lastUpdateTime = 0;

//Multi-channel gas sensor
float cNH3;
float cCO;
float cNO2;
float cCH4;
float cH2;

ESP8266Client client;

void setup()
{
Serial.begin(9600);
Serial.println("Start");
//Multi-channel sensor setup
gas.begin(0x04);
gas.powerOn();
//WIFI connection
wifi.begin(2, 3);
if (!wifi.connectAP(ssid, pass))
{
Serial.println(F("Error connecting to WiFi"));
}
Serial.print("Connected to ");
Serial.println(wifi.SSID());
Serial.println(wifi.localIP());
ThingSpeak.begin( client );
}

void loop()
{
if (millis() - lastUpdateTime >= postingInterval)
{
//Multi-channel gas sensor
cNH3 = gas.measure_NH3();
cCO = gas.measure_CO();
cNO2 = gas.measure_NO2();
cH2 = gas.measure_H2();

Serial.print("NH3 is ");
Serial.println(cNH3);
Serial.print("CO is ");
Serial.println(cCO);
Serial.print("NO2 is ");
Serial.println(cNO2);
Serial.print("H2 is ");
Serial.println(cH2);

write2TSData( channelID , dataFieldOne , cNH3, dataFieldTwo, cCO, dataFieldThree, cNO2, dataFieldFour, cH2);
delay(10000);
}
}

float writeTSData( long TSChannel, unsigned int TSField, float data )
{
float writeSuccess = ThingSpeak.writeField( TSChannel, TSField, data, writeAPIKey ); // Write the data to the channel
while ( writeSuccess )
{
Serial.println( String(data) + " written to Thingspeak." );
}
return writeSuccess;
}

float write2TSData( long TSChannel, unsigned int TSField1, float field1Data, unsigned int TSField2, long field2Data, unsigned int TSField3, long field3Data , unsigned int TSField4, long field4Data)
{
ThingSpeak.setField( TSField1, field1Data );
ThingSpeak.setField( TSField2, field2Data );
ThingSpeak.setField( TSField3, field3Data );
ThingSpeak.setField( TSField4, field4Data );

float writeSuccess = ThingSpeak.writeFields( TSChannel, writeAPIKey );
return writeSuccess;
}

 

PLEASE PLEASE PLEASE help me.

Avatar
cstapels
Moderator
Forum Posts: 158
sp_UserOfflineSmall Offline
2
January 31, 2018 - 8:27 pm
sp_Permalink sp_Print

What exactly is the problem?  Your channel does not seem to be public at present.  

I am curious about the while loop:

while ( writeSuccess )
{
Serial.println( String(data) + " written to Thingspeak." );
}

if writeSuccess is true, wont this loop forever?

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
38 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:

ibgedubo

aogomaeqaza

ureomug

itixuwidouzuv

eilimir

memozupi

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee