Hi everybody!
I’m using a Spark Core to send data to an Emoncms private database:
everything was going right
but unfortunately I deleted the sketch (damn!).
Now I’m not able to write another one working,
I’m sure the one I’m struggling around is full of stupid mistakes…I can’t see.
And ok, sending data via browser (http://xxxxxxxxxx.noip.me/emoncms/input/post.json?node=1&json={power:150,light:78}&apikey=445d983840daa4288430fa9c9d7434cc)
or curl works fine.
So…what?
Please, anyone can help?
My sketch:
// This #include statement was automatically added by the Particle IDE.
#include "HttpClient/HttpClient.h"
// This #include statement was automatically added by the Particle IDE.
#include "spark-dallas-temperature/spark-dallas-temperature.h"
// This #include statement was automatically added by the Particle IDE.
#include "OneWire/OneWire.h"
#define ONE_WIRE_BUS D2
#define DEVICE_ID "51ff6c065082554916540123"
#define TOKEN "7327a3859afda46ba2eb1d326b7b1d1e1251123f"
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensor(&oneWire);
double temperature = 0.0;
int light = 0;
int humidity=0;
HttpClient http;
http_header_t headers[] = {
{ "Content-Type", "application/json" },
{ "X-Auth-Token" , TOKEN },
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Particle.variable("temp", &temperature, DOUBLE);
Particle.variable("light", &light, INT);
sensor.begin();
sensor.setResolution(12);
request.hostname = "xxxxxxxxxx.noip.me/emoncms";
// request.ip = {192,168,1,104};
request.port = 80;
Serial.begin(9600);
}
void loop() {
sensor.requestTemperatures();
temperature= sensor.getTempCByIndex(0);
light = analogRead(A0);
humidity=light/10;
Serial.println(temperature);
Serial.println(light);
// request.path = "/input/post.json?apikey=445d983840daa4288430fa9c9d7434cc&node=1&json=";
request.path = "/input/post.json?apikey=445d983840daa4288430fa9c9d7434cc&node=1&json={power:122,light:30}";
// request.body = "{power:122,light:30}";
//request.body = "{\"power\":" + String(light) + "}";
// http://192.168.1.104/emoncms/input/post.json?node=1&json={power:150,light:78}&apikey=445d983840daa4288430fa9c9d7434cc
http.post(request, response, headers);
//Serial.printl(request.body);
//Serial.println("000000");
//Serial.println(response.status); //For debug only
Serial.println(humidity);
// Serial.println(response.body);
delay(20000);
}