i've found that in the forum and it do the job as i expect.
console.log("hex:",d.charCodeAt().toString(16));
the module send some char and the last one is the SUM of the transmitted string.
i wrote something like that (i did not test it on the espruino)
let sum=0;
let buf = new Uint8Array();
function checkAnswer(buff) {
console.log(buff.toString(16));
switch (buff[1]) {
case 0x01: // status
console.log("status:",buff[3]);
break;
case 0x0C: //total audios
console.log("total audios:",buff[3],buff[4]);
break;
case 0x0D: //current audio
console.log("current audio:",buff[3],buff[4]);
break;
default:
break;
}
// reset first buffer
buf = new Uint8Array();
}
s.setup(9600,{rx:B6, tx:B5});
s.on('data', function(d) {
console.log("hex",d.charCodeAt().toString(16).toUpperCase());
let nd = d.charCodeAt();
buf.push(nd);
sum+= nd;
if (sum == nd && buf.length >1) {
// fin de la transmission
buf.pop(); // efface le sum du buffer
sum = 0;
checkAnswer(buf);
}
});
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.
Hello Markus,
a Happy new Year.
i've found that in the forum and it do the job as i expect.
the module send some char and the last one is the SUM of the transmitted string.
i wrote something like that (i did not test it on the espruino)
regards