I created an HTTP POST node and linked the imp node to the POST soft node in the planner. I am unable to send to our server anything other than one integer number from the imp and in any case never a float number. The imp server seems to receive the data correctly even if on the planner, the "server.show" numbers stays on the planner only for an instant.
The code I am running is below and my server (RoR log) gets:
Started POST "/api/impUpload" for 184.169.136.13 at 2012-08-09 22:07:37 +0000
Processing by Api::DevicesController#impUpload as HTML
Parameters: {"value"=>"778", "target"=>"30731e5e118cbee7", "channel"=>"1"}
Rendered text template (0.0ms)
Completed 200 OK in 1ms (Views: 0.7ms | ActiveRecord: 0.0ms)
My server receives the proper HTTP request with the method POST as expected. However, i receive only the constant 778 in the "value" in the payload, and only if the output variable contains an integer. If I try to send for instance only the temperature as in the code below, my server doesn't receive the POST at all.
Please advise.
Thanks,
-Marco G.
// Code sample
server.log("test started");
hardware.configure(I2C1_89);
local i2c = hardware.i2c1;
local out_number = OutputPort("Number", "number"); // send a constant
local out_temp = OutputPort("Temperature", "number");
local out_humid = OutputPort("Humidity", "number");
// Register with the server
imp.configure("NebulaTemp", [], [out_number,out_temp, out_humid]);
local function change() {
local number = 778;
local temperature = 0.01;
local humidity = 0.02;
// Start conversion
i2c.write(0x4e, "");
// Wait at least 36ms
imp.sleep(0.05);
// Read out temperature and humidity, zero length subaddress means the write
// subaddr phase will be totally skipped and we'll just do the read
local th = i2c.read(0x4e, "", 4);
// note data will be marked as stale because each read kicks off another
// cycle as we always do a write-before-read on i2c
// hence, we need to mask top bits of humidity byte
// Form temp and humidity
local temperature = ((((th[2] <> 2)) * 165) / 16383.0) - 40;
local humidity = ((((th[0] & 0x3F) << 8 ) | (th[1] )) / 163.83 );
// Log and show
server.log(format("number %d temperature %.2fC humidity %.2f%%", number, temperature, humidity));
server.show(format("%d %.2fC %.2f%%", number, temperature, humidity));
// Send data to server
out_number.set(number);
out_temp.set(temperature);
out_humid.set(humidity);
}
change();
server.sleepfor((1 * 30));