Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sending POST requests to ThingSpeak channel from Arduino YUN
#include <Bridge.h>
#include <Console.h>
#include <Process.h>
#include <DHT.h>
DHT dht;
#define Vref 4.95
#define ARRAY_SIZE 4
#define DHTPIN 7
void setup() {
Serial.begin(9600);
Bridge.begin();
Console.begin();
dht = DHT(DHTPIN,DHT22);
};
void postToThingSpeak(String key, float value[]) {
Process p;
String cmd = "curl --data \"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();
}
void loop() {
float vol[ARRAY_SIZE];
int sensorValue = analogRead(A0);
int sensorValue2 = analogRead(A1);
vol[0]=(float)sensorValue/1023*Vref;
vol[1]=(float)sensorValue2/1023*Vref;
vol[2] = dht.readTemperature();
vol[3] = dht.readHumidity();
postToThingSpeak("XXXXXXXX",vol);
delay(2*60000);
}
a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment