ThingSpeak problems with upload | 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
ThingSpeak problems with upload
No permission to create posts
April 22, 2017
5:04 am
Avatar
Griwen
New Member
Members
Forum Posts: 3
Member Since:
April 22, 2017
sp_UserOfflineSmall Offline

Hello!
I have Arduino Uno WiFi, and the temperature sensor DHT21. Problem starts when I try to upload my values from sensors to ThingSpeak. When I try to upload more than two fields in rest uri, it's not working, when its two or one field i can upload this values without problems.

#include "DHT.h"
#include <Wire.h>
#include <UnoWiFiDevEd.h>

#define CONNECTOR "rest"
#define SERVER_ADDR "api.thingspeak.com"

#define APIKEY_THINGSPEAK "****************" //Insert your API Key

#define DHTPIN 2 // modify to the pin we connected
#define DHTPINN 3 // modify to the pin we connected
#define DHTTYPE DHT21 // AM2301
DHT dht(DHTPIN, DHTTYPE);
DHT dhtt(DHTPINN, DHTTYPE);

short hum = 60;
short temp = 22;
short hum1 = 65;
short temp1 = 25;

void setup() {
Ciao.begin(); // CIAO INIT
Serial.begin(9600);
dht.begin();
dhtt.begin();
}

void loop() {
int h = dht.readHumidity();
float t = dht.readTemperature();
int ha = dhtt.readHumidity();
float ta = dhtt.readTemperature();

Ciao.println(h);
Ciao.println(t);
Ciao.println(ha);
Ciao.println(ta);

String uri = "/update?api_key=";
uri += APIKEY_THINGSPEAK;
uri += "&field1=";
uri += String(h);
uri += "&field2=";
uri += String(t);
uri += "&field3=";
uri += String(ha);
uri += "&field4=";
uri += String(ta);

Ciao.println("Send data on ThingSpeak Channel");

CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, uri);
if (!data.isEmpty()){
Ciao.println( "State: " + String (data.get(1)) );
Ciao.println( "Response: " + String (data.get(2)) );
}
else{
Ciao.println("Write Error");
}

delay(30000); // Thinkspeak policy

}

 

When I put only two fields it works:

String uri = "/update?api_key=";
uri += APIKEY_THINGSPEAK;
uri += "&field1=";
uri += String(h);
uri += "&field2=";
uri += String(t);

 

Console:

Send data on ThingSpeak Channel
Write Error
29
26.10
25
26.40
Send data on ThingSpeak Channel
Write Error
29
26.20
30
26.40
Send data on ThingSpeak Channel
State: 400
Response:

April 22, 2017
7:16 am
Avatar
rw950431

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

Perhaps you can try to print the url to console or maybe just the length to see how long it is?  Perhaps you are exceeding some kind of buffer length somewhere..   You could also experiment by adding  "&status=xxx" then gradually increasing the length until you trigger the error.

 

Maybe you could also add a delay between the write and the isdataEmpty() to make sure there is no timing problem.

April 22, 2017
8:21 am
Avatar
Griwen
New Member
Members
Forum Posts: 3
Member Since:
April 22, 2017
sp_UserOfflineSmall Offline

In console with two value it works from sensors:

Send data on ThingSpeak Channel
/update?api_key=**********&field1=22&field2=36
State: 200
Response: 131

In console three sensors but not float

Send data on ThingSpeak Channel
/update?api_key=**********&field1=22&field2=36&field3=24
State: 200
Response: 142

It works

From 4 sensors it doesnt work
Send data on ThingSpeak Channel
/update?api_key=**********&field1=22&field2=36&field3=30&field4=13
Write Error
Send data on ThingSpeak Channel
/update?api_key=**********&field1=22&field2=36&field3=30&field4=12
State: 400
Response: 

So the problem can be the length, but i need to upload two float values like 10.09 and two short values line 50.
 
 










April 23, 2017
10:36 am
Avatar
Vinod

MathWorks
Members
Forum Posts: 202
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

Take a look at one of the examples that use the ThingSpeak support library:

https://github.com/mathworks/thingspeak-arduino/tree/master/examples

More specifically try modifying this one:

https://github.com/mathworks/thingspeak-arduino/tree/master/examples/WriteMultipleVoltages

Does that work?

Forum Timezone: America/New_York

Most Users Ever Online: 114

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

BarryMaync, ThomasRougs, DonaldGen, prince, JrGordon, Elamsweems

Administrators: Hans: 387, lee: 457