I’ve been working on this for about a week now - learning by reading, trial and error - more reading. It’s been about a week and I’ve gotten pretty far considering I started with nothing. The basics are this:
I have a energy monitoring board (openenergymonitor.org) TX3 which I connected an April Imp to via serial UART57. I went from getting a stream of integers to being able to send an array to the agent, which then posts to my own webserver. I have all the bits I think, but I’m stuck on how to try and format my JSON stream.
The array from the Device is:
[agent] [ "9", "9", "1215", "245", "0", "11838" ]
It represents:
["node", "sensor1", "sensor2", "sensor3", "sensor4", "ACVolts"]
The array reaches the agent (after lots of trial and error), but I’m stuck trying to figure out how to pull the integers from the array with the correct inputs for the JSON stream.
The format of the JSON should be:
http://staging.mywebsite.com/emoncms/input/post.json?json={node:"9",sensor1:”9”,sensor2:”1215”,sensor3:”245”,sensor4:”0”,ACvolts:"118.38"}&apikey=xxxxxxxxxxxxxxxxxxxx
I know the JSON format is right from making a manual post and getting values, but I can’t for the life of me figure out how to take the variables from the array and preface them with the correct values. I’ve been scratching my head for a day or so trying to sort out the best way to do this. The website auto updates, so as long as the JSON stream is there, it will update.
I won’t bore with my Device code, but here is my current Agent code:
device.on("senddata", function(data){
local data = (data)
sensor =// Set URL to your web service
local url = mywebsite.com is available for purchase - Sedo.com";// 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();
});
I’d really appreciate some guidance. I feel like the solution is just around the corner, but I can’t quite see it. I’m sure if someone can give me a bit of a shove it will all fall into place. I’m more than an newbee when it comes to coding - so everything is a learning experience. The forums and the documentation are great - and I keep referencing them for help. I managed to get A->B->C, but need some help getting C->D (the website in JSON).
I’m sure I’m missing something simple - just not sure what.