Hi
I have an particle Argon and trying to do a HTTP.GET to a php site that will update an sql database with some sensor data. But my code wont work as I want. What am I doing wrong?
// This #include statement was automatically added by the Particle IDE.
#include <HttpClient.h>
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>
#define DHTPIN D4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
// { "Content-Type", "application/json" },
//{ "Accept" , "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float t = dht.getTempCelcius();
if (isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Particle.publish("temp", String (t));
request.hostname = "test.mysite.com";
request.port = 80;
request.path = "/index.php?deviceid=" + System.deviceID() + "&variable=temp&value=" + t;
Particle.publish("Publish", request.path);
http.get(request, response, headers);
Particle.publish("BodyStatus", response.body);
delay(30000);
}
When I post this url in a webbrowser it all works fine, and the DB is updated with new data.
" http://test.mysite.com/index.php?deviceid=ABC123&variable=temp&value=26.000000"
Thanks / Johan
Sorry for being pedantic, but what do you want to get back with that request?
While a GET request may be easier to test with a browser, putting data into a DB would usually be done via a PUT or maybe POST request 
You do Particle.publish("PUBLISH", request.path)
but don’t show what that gives you 
However, try + String(t)
instead of + t
.
Also, what is your response.status
?
Sorry, I'm new to this so that is why not all of it is OK. 
I do a Particle.publish just to see so the request.path is looking right.
Have changed to String instead of just t
and the response.status is -1
I have tried something similiar with this code
#include <HttpClient.h>
HttpClient http;
http_header_t headers[] = {
//{ "Content-Type", "application/json" },
//{ "Accept" , "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
IPAddress serverIP(192, 168, x, y);
void setup() {
Serial.begin(9600);
}
void loop() {
float t = 123.45;
char path[128];
snprintf(path, sizeof(path), "/index.php?deviceid=%s&variable=temp&value=%.2f", (const char*)System.deviceID(), t);
Serial.println(path);
//request.hostname = "test.mysite.com";
request.ip = serverIP;
request.port = 80;
request.path = path;
http.get(request, response, headers);
Serial.printlnf("Response (%d): <%s>", response.status, (const char*)response.body);
delay(5000);
}
Hitting this test server on my own network
var http = require('http');
//create a server object:
http.createServer(function (req, res) {
console.log(req.rawHeaders);
console.log(req.url);
res.write('Hello World!'); //write a response to the client
res.end(); //end the response
}).listen(80); //the server object listens on port 8080
And what should I say, it worked as expected 