You are reading a single comment by @d0773d and its replies.
Click here to read the full conversation.
-
@allobjects.. Ok, i think I get it. How do I access sensorObject to gather the values when using code:
var sensorObject = { "restempvalue" : 0, "phvalue" : 0, "ecvalue" : 0 };
Nevermind... I read over your posts again.. I was just a bit confused, before. Thanks for the informative response.
sensorReadings
is already an object... andJSON.parse(aJSONString)
expects a string as argument... ;-), therefore, expressionvar sensorObj = JSON.parse(sensorReadings);
throws error (in Browser:...Uncaught SyntaxError: Unexpected token o in JSON at position 1(ā¦)
; what error is thrown in Espruino I cannot figure out right now, because have no Espruino (or emulator) at hand).This code (see second line)
fixes your issue, but there is not point to first build a JSON string from
sensorReadings
object and second - right away - parse that JSON string back into an object... ;-)Plain assignment gets you there - because it is the same:
Therefore, you can drop
sensorReadings
completely and just use:It is a different story though when you want to write you readings onto a SD memory card, or transmit to wherever. For that you would
A) for initialization
sensorReadings
objectJSON.stringify()
to asensorReadingsAsString
stringsensorReadingsAsString
string to the storage;B) for update that readings on the storage, you
sensorReadingsAsString
JSON.stringify()
to asensorReadingsAsString
stringsensorReadingsAsString
string 'back' to the storage