6:21 pm

August 12, 2018

When using the following function from thingspeak lib, it works, data are displayed to thingspeak : ThingSpeak.writeField(myChannelNumber, 1, Temp, myWriteAPIKey)
Now, when using the function ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey) along with ThingSpeak.setField(1,Temp), nothing is displayed.
Any advise would be appreciated ; I've attached the code below.
Chris
#include
#include
#include
#include
#include
#include "ThingSpeak.h"
HDC1000 mySensor;
// MAC address for your Ethernet shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xD8, 0x2E };
// Thinkspeak to upload data
unsigned long myChannelNumber = 394883;
const char * myWriteAPIKey = "D5VW1M5CUC6XWSSG";
// Set the Ethernet library structures :
EthernetClient client;
// Declares variables and other fixed values :
float WatchDog = 0;
unsigned long PreviousClicksMillis;
int uTemp;
int uHumidity;
int udp;
int uWindSpeed;
unsigned volatile int Clicks = 0; // interrupt number 0 on digital pin 2
int SAMPLING_RATE = 1000; // Sampling rate in ms
int T = 30 * SAMPLING_RATE; // Integration time in s
float N = float(T / SAMPLING_RATE); // Number of samples per integration time
void setup(){
// Start Serial Monitor
Serial.begin(9600);
Serial.println("Starting Datapod init!");
// Init HDC1000 sensor :
mySensor.begin();
// Inititiate Click count for WindSpeed measurement
attachInterrupt(0, clicker, RISING);
PreviousClicksMillis = millis();
// Initializing network
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again ...");
delay(15000);
}
// Network success message :
delay(2000);
Serial.print("Network initialized with the following IP address : ");
// Print the local IP address :
for (byte thisByte = 0; thisByte < 4; thisByte++)
{
// Print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println(); Serial.println();
// Initializing Thingspeak :
ThingSpeak.begin(client);
}
void loop(){
// Init values :
float Temp = 0.;
float Humidity = 0.;
float WindSpeed = 0.;
float dp = 0.; // Dewpoint
for (int Sampler = 0 ; Sampler < T ; Sampler += SAMPLING_RATE)
{
// Clicks and Rotates timing references :
unsigned long loopstart = millis();
//
Temp += mySensor.getTemp();
Humidity += mySensor.getHumi();
//
unsigned long loopend = millis();
delay(SAMPLING_RATE - (loopend - loopstart)); // T)
{
unsigned long now = millis();
float CountTime = (now - PreviousClicksMillis) / 1000.0;
// Serial.println(CountTime); // For debug purpose only
WindSpeed = .765 * ((float) Clicks / CountTime);
// WindSpeed = (float) Clicks / 1.; // For debug purpose only
Clicks = 0;
PreviousClicksMillis = now;
}
// WatchDog :
WatchDog += 1;
// Thingspeak
/*ThingSpeak.writeField(myChannelNumber, 1, Temp, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 2, Humidity, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 3, dp, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 4, WindSpeed, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 5, WatchDog, myWriteAPIKey); */
ThingSpeak.setField(1,Temp);
ThingSpeak.setField(2,Humidity);
ThingSpeak.setField(3,dp);
ThingSpeak.setField(4,WindSpeed);
ThingSpeak.setField(5,WatchDog);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
}
// Functions :
// COUNT clicks from anemometer
void clicker()
{
Clicks++;
}
4:20 pm


Moderators
March 7, 2017

If you use the code above, you will violate the update rate.
Each thingspeak.writeField() counts as an update. If you have a paid license, you need at least 1 second of delay between each write. If you have a free account you need 15 seconds.
You can use ThingSpeak.setField() five times in a row without waiting, but each ThingSpeak.writeFields() also counts as an update. Since there was just a writeField() behind it, it would violate the update frequency.
Did you commented out the ThingSpeak.writefields() when you tested?
Also, I noticed in your data that there are line feeds in your field 5 data i.e. "400
" Are these on purpose? They may make your field 5 ThingSpeak plots not function correctly.
Most Users Ever Online: 166
Currently Online:
28 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
Advantagetreeexperts, laundrydaddyuk, techhhelp5, ken, tran, huldacormierModerators: cstapels: 460
Administrators: Hans: 405, lee: 457