You are reading a single comment by @d0773d and its replies. Click here to read the full conversation.
  • My goal is to calculate sensor readings and then save them to a JSON object then console.log output a specific value. I'm not sure why I'm not able to access my json value. I keep getting error:

    Uncaught Error: Field or method "restempvalue" does not already exist, and can't create it on undefined
     at line 153 col 10
    sensorObj.restempvalue = val;
             ^
    

    code:

    var sensorReadings = { "restempvalue" : 0, "phvalue" : 0, "ecvalue" : 0 };
    var sensorObj = JSON.parse(sensorReadings);
    
    function getAllSensorData() {
      /*restemp.takeReading(function(val) {
        console.log(val);
      });
    
      ph.takeReading(function(val) {
        console.log(val);
      });*/
    
      ec.takeReading(function(val) {
        sensorObj.restempvalue = val;
        console.log(val);
      });
    }
    
About

Avatar for d0773d @d0773d started