Sample code on Mac that is causing no issues when sending to a Espruino device after two time JSON5.stringify() like this:
var noble = require('@abandonware/noble');
const JSON5 = require('json5');
var aJS = {txt : "012345\nabcde\näöüß"};
var saJS5 = JSON5.stringify(aJS);
// {txt:'012345\nabcde\näöüß'}
var sa2JS5 = JSON5.stringify(saJS5);
// {txt:'012345\\nabcde\\näöüß'}
var COMMAND = `\x03\x10transfer(${sa2JS5})\n`;
// transfer("{txt:'012345\\nabcde\\näöüß'}")
// use https://www.espruino.com/Interfacing Node.js / JavaScript
// added some seconds before calling disconnect to catch more data
sample code on PuckJS
transfer = function (saJS5) {
var aJS5;
try {
aJS5 = eval('('+saJS5+')');
} catch(e){
console.log("error in eval:",e);
}
}
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Sample code on Mac that is causing no issues when sending to a Espruino device after two time
JSON5.stringify()
like this:sample code on PuckJS