Results for
Hi,
I have this code posting data. It used to work a couple of years back but now it shows no new data being posted and I want to see what the error is:
#include <Bridge.h> #include <BridgeServer.h> #include <BridgeClient.h> #include <DHT.h>
#define DHTPIN 4 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE);
//********************
#define ARRAY_SIZE 2 String API = "13xxxxxxxxxxxxx";
unsigned long previousMillis = 0; // will store last time LED was updated const long interval = 900000; // interval at which to blink (milliseconds)
void setup() {
Bridge.begin();
Console.begin();
dht.begin();
Serial.begin(9600);
Serial.println("set up");
}
//********************
void postToThingSpeak(String key, float value[]) {
Process p;
String cmd = "curl -d \'key="+key;
for (int i=0;i<ARRAY_SIZE;i++) {
cmd = cmd + "&field"+ (i+1) + "=" + value[i];
}
cmd = cmd + "\' http://api.thingspeak.com/update";
p.runShellCommand(cmd);
Console.println(cmd);
p.close();
Serial.println("posted");
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis; float temperature = dht.readTemperature();
//float temperature = 33.33;
Console.println(temperature);
float humidity = dht.readHumidity();
//float humidity = 44.44;
Console.println(humidity);
float vol[ARRAY_SIZE];
vol[1] = temperature;
vol[0] = humidity;
postToThingSpeak(API, vol); //ACCOUNT
}
//delay(120000); // ThingSpeak will only accept updates every 15 seconds.
}