Quantcast
Channel: ThingSpeak IoT Community - Forum: Arduino
Viewing all articles
Browse latest Browse all 172

Griwen on ThingSpeak problems with upload

$
0
0

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:


Viewing all articles
Browse latest Browse all 172

Trending Articles