REST api

I have had problems since planner disappeared. Did not manage to get the agent to work, I am using this example:http://electricimp.com/docs/api/http/jsonencode/

I’m no programmer and had I known a planner would end, I had not bought any IMP. But I want to get the ones I have to work.
On line 6 of this (local headers), I get “expected ‘IDENTIFIER’”. What IDENTIFIER?
And will this work? I want to send the temperature to my server.
Agent:
`device.on(“senddata”, function(data) {
// Set URL to your web service
local url = “http://myownserver.com:6001/api/tag/string/imptemp?value=”;

// Set Content-Type header to json
local headers = { “Content-Type”: “application/json”);

// encode data and log
local body = http.jsonencode(data);
server.log(body);

// send data to your web service
http.post(url, headers, body).sendsync();
});`

It looks like a typo on the content type line with the bracket vs parenthesis.

Sorry, there was a typo in the example as @mlseim noted. It’s fixed now. The line should read:

local headers = { "Content-Type": "application/json" };

Ok, thanks for your help.
I get error on my server when I use jsonencode but changed to “Content-Type”: “application / x-www-form-urlencoded” to avoid it.
But I get no value, the log shows that the agent receives the value.
2014-02-01 13:06:22 UTC-1: [Status] Device booting; 2:53% program storage used
2014-02-01 13:06:22 UTC-1: [Device] The temperature in the room 23.213
2014-02-01 13:06:22 UTC-1: [Agent] 23.2132

To send to my server from the browser, it should look like this: http://myownserver.com:6001/api/tag/string/imptemp?value=23.213
but the log in my server says when the agent sends: /api/tag/string/imptemp?value=
How should I do to send value after the =?

In that case you’d need to append the value to url before passing it to http.post()

Thanks for your reply.
Now it worked but only when I press “Build and run”, it is not automatically updated every 30 seconds as it does in the log. How do I make that happen?

device.on("senddata", function(data) { // Set URL to your web service local url = "http://myownserver:6001/api/tag/string/imptemp?value=";

// Set Content-Type header to json
local headers = { “Content-Type”: “application/x-www-form-urlencoded” };
local url = (url + data);
// encode data and log
local body = http.jsonencode(data);
server.log(body);

// send data to your web service
http.post (url, headers, body).sendsync();

});

Can you post your device code?

// April with a 10k, 1% from 3V3 to pin9 and 10k B57861S0103F040 NTC Thermistor from pin9 to ground // pin9 ANALOG NTC value

// Configure Pins
// pin 9 is the middle of the voltage divider formed by the NTC - read the analog voltage to determine temperature
hardware.pin9.configure(ANALOG_IN);

// all calculations are done in Kelvin
// these are constants for this particular thermistor; if using a different one,
// check your datasheet
const b_therm = 3988;
const t0_therm = 298.15;

// Output structure for sending temperature to server
local tempOut = (“Temperature ©”, “number”);
local tempOutStr = (“Temperature ©”, “string”);

function getTemp() {
// scale the ADC reading to a voltage by dividing by the full-scale value and multiplying by the supply voltage
local v_therm = 3.3 * hardware.pin9.read() / 65535.0;
// calculate the resistance of the thermistor at the current temperature
local r_therm = 10000.0 / ( (3.3 / v_therm) - 1);
local ln_therm = math.log(10000.0 / r_therm);

local t_therm = (t0_therm * b_therm) / (b_therm - t0_therm * ln_therm) - 273.15;

  
// Celsius
local c = (t_therm)
// format into a string for the string output port
local c_str = format("%.02f", c)
server.log("Temperature "+c_str+""); 

// emit values to our output ports
tempOut =(c);
tempOutStr = (c_str);

//sec
imp.wakeup(30, getTemp);

}

getTemp();
local data = (tempOutStr);
agent.send(“senddata”, data );

agent.send needs to be called from inside the getTemp function, since that’s what is being called every 30 seconds. Try moving your last two lines to just before the call to imp.wakeup.

L-)
Perfect!!! It works :stuck_out_tongue:
Thank you very much for your help.