Write multiple fields all at once using thingspeak library | 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
Write multiple fields all at once using thingspeak library
No permission to create posts
August 12, 2018
6:21 pm
Avatar
cotixtof
New Member
Members
Forum Posts: 1
Member Since:
August 12, 2018
sp_UserOfflineSmall Offline

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++;
}

August 13, 2018
4:20 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 365
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

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.

Forum Timezone: America/New_York

Most Users Ever Online: 114

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

Georgesic, BalladolbineAboth, Wayneamure, MattonAboth, ginatm2, Spreeuw

Administrators: Hans: 387, lee: 457