Skip to content

Instantly share code, notes, and snippets.

@netmaniac
Created April 16, 2014 20:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netmaniac/10930106 to your computer and use it in GitHub Desktop.
Save netmaniac/10930106 to your computer and use it in GitHub Desktop.
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