I use an arduino mega to upload the status of lightswitches and powersockets to emoncms
but the code gets really long when you use for example this code about 15 times for different lightswitches/powersockets to update the status troughout the code
The great thing about JSON is that you could pass arrays of data(all your sensors and data) inside one array, like containers, so all you need to do is to create an array and the pass it in your JSON object.
The the emoncms you have a helper page showing you that.
See here:
Domotica.ino:1382:21: error: ‘device’ was not declared in this scope
Domotica.ino:1383:21: error: ‘status’ was not declared in this scope
@HugoPT : I'm allready using arrays to upload temperature and thermostat data, but for single lightswitches, there is no need for an array, because you use only 1 lightswitch at a time, it wouldn't make sense to update 15 lightswitches statuses if you only switch 1 on or off
@HugoPT : I'm allready using arrays to upload temperature and thermostat data, but for single lightswitches, there is no need for an array, because you use only 1 lightswitch at a time, it wouldn't make sense to update 15 lightswitches statuses if you only switch 1 on or off
In an int variable you could pass 16 status of lightswitchs or anything you want.
Passing that int to emoncms is trivial and does not put to much overhead.
char device[] = "livingroom"?
If I use that code it compiles but it only puts the "1" in the emoncms in the field where the name is suposseds to go instead of the number field
char device is just a pointer to string livingroom and it point to the first memory position which contains "l"
Maybe this way:
client.print("GET /emoncms/input/post.json?apikey=xxxxxxxxxxxxxxxxxxxxxxxxxxx&json={");
client.print(*device);//Print what the pointer is pointing to
The arguments device and status have local scope inside the function and will hide any global variables of the same name. The values of these arguments are determined by what is passed in when the function is called. I might be able to help more if you post your code.
wich is about 2100 lines of codes, and removed everything from it that I didn't need, like setting timers to activate the heating, wich i can also do from my android phone with Tasker, and then I cleaned up the code to reduce it to about 850 lines of code, and changed everything, to store data on emoncms, instead of saving it in EEPROM, because the code was doing like writes to EEPROM every 5 minutes, and I read in the documentation on this site that the EEPROM memory of an arduino only allows for 100.000 write cycles, so then basicly after a year of usage the arduino's EEPROM memmory would be destroyed, so then changed code to store stuff in emoncms instead of EEPROM and added about 750-800 lines of own code (and used code from other sketches), to basicly controll everything in my home, powerswitches, lightswicthes, send RF and Infrared signals to control stuff like amplifier, tv, lights, beamerscreen, send wake on lan to start htpc, intercept RF signal from doorbell to send message to my phone/tablet, etc...
I marked the code I added with comments: // Mijn code, and // Einde mijn code, wich translates to // My Code, and // End of my code
too long to post here about 1600 lines of code, so put it here: