• I would like to append a \r\n to my JSON.stringify before submitting the values to Serial1. I have:

    function getSensorData() {
      var resTemp = getResTempValue(10);
      var roomTemp = 98.00;
      var ph = 58;
      var ec = 700;
    
      outputSensorData(resTemp.toFixed(2), roomTemp, ph, ec);
    }
    
    function outputSensorData(resTempVal, roomTempVal, phVal, ecVal) {
      var sensorData = {resTemp:resTempVal, roomTemp:roomTempVal, ph:phVal, ec:ecVal};
    
      Serial1.print(JSON.stringify(sensorData)­);
    }
    

    My Terminal window shows the json properly. However, every time the json data gets sent, the next line shows right next to the earlier json data instead of underneath. I need to append a \r\n so the string that is sent will show on the next line. How do I achieve that?

  • could you use Serial1.println instead of Serial1.print?

  • @Gordon That worked, thanks! I didn't know println existed. I need to read the documentation more closely.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

append a \r\n to a JSON.stringify before sending to Serial1?

Posted by Avatar for d0773d @d0773d

Actions