-
Also this is the code running on my thingy device:
https://github.com/bakon11/openrpcThingy52/blob/master/server/typescript/src/devices/thingy52.jsI noticed that it actually does execute the function each time, but it disconnects before the call back fires off back to node JS and my data comes back undefined.
-
Hey guys.
So I have the nordic thingy52 with espruino 1v98 since I can't flash newer versions due to locked bootloader.
Anyways, I wrote a small program to run on it to basically collect some sensor data and store them in typed arrays in the ram, and a small data extraction function based on some examples from espruino.
Everything actually works great, the problem I'm having is when using the espruino NPM package(https://www.npmjs.com/package/espruino).
Im using the example to run expresion function on the device.
import { GetSensorData } from "../generated-typings"; var esp = require("espruino"); const getSensorData: GetSensorData = (deviceID, sensorType) => { return Promise.resolve(querySensors(deviceID, sensorType)); }; const querySensors = (deviceID:any, sensorType: any):Promise<any> => { return new Promise((resolve, reject) => { esp.init((data:any) => { esp.expr(deviceID, 'exportData('+sensorType+')', function(data:any){ // resolve(JSON.parse(data)); resolve(data); console.log("your data:" + data); // return(data); }); }); }); } // queryPressure("e5:b6:7f:eb:a0:dd"); export default getSensorData; });
And on first call it works great and returns data to my app, however when I do the same call again I get unable to connect error:
Already initialised. Already initialised. BT> Connecting BT> Connected Connected {} BT> send "\n" Received a prompt after sending newline... good! Sending... ---> "\u0010print(\"<\",\"<<\",JSON.stringify(process.env),\">>\",\">\")\n" BT> send "\u0010print(\"<\",\"<<\",JSON" BT> send ".stringify(process.e" BT> send "nv),\">>\",\">\")\n" Sent Receiving... Got "< << {\"VERSION\":\"1v98\",\"GIT_COMMIT\":\"1e06400\",\"BOARD\":\"THINGY52\",\"FLASH\":524288,\"RAM\":65536,\"SERIAL\":\"50a977b6-bf9ebbea\",\"CONSOLE\":\"Bluetooth\",\"MODULES\":\"Flash,Storage,BH1745,Thingy,LPS22HB,HTS221,CCS811,MPU9250,LIS2DH12\",\"EXPTR\":536882356} >> >\r\n>" Found THINGY52, 1v98 Loading http://www.espruino.com/json/THINGY52.json Board JSON loaded Firmware >1.43 supports faster writes over USB Set Slow Write = false FIRMWARE: Current 1v98, Available 2v05 BT> send "\n" Received a prompt after sending newline... good! Sending... ---> "\u0010print(\"<\",\"<<\",JSON.stringify(exportData(temp)),\">>\",\">\")\n" BT> send "\u0010print(\"<\",\"<<\",JSON" BT> send ".stringify(exportDat" BT> send "a(temp)),\">>\",\">\")\n" Sent Receiving... Got "< << [{\"date\":{\"ms\":1588436637},\"sensor\":\"22.31\"},{\"date\":{\"ms\":1588436641},\"sensor\":\"22.29\"},{\"date\":{\"ms\":1588436645},\"sensor\":\"22.23\"},{\"date\":{\"ms\":1588436649},\"sensor\":\"22.23\"},{\"date\":{\"ms\":1588436653},\"sensor\":\"22.16\"},{\"date\":{\"ms\":1588436657},\"sensor\":\"22.14\"},{\"date\":{\"ms\":1588436661},\"sensor\":\"22.18\"},{\"date\":{\"ms\":1588436665},\"sensor\":\"22.19\"},{\"date\":{\"ms\":1588436669},\"sensor\":\"22.16\"},{\"date\":{\"ms\":1588436673},\"sensor\":\"22.10\"},{\"date\":{\"ms\":1588436677},\"sensor\":\"22.16\"},{\"date\":{\"ms\":1588436681},\"sensor\":\"22.21\"},{\"date\":{\"ms\":1588436685},\"sensor\":\"22.21\"},{\"date\":{\"ms\":1588436689},\"sensor\":\"22.18\"},{\"date\":{\"ms\":1588436693},\"sensor\":\"22.14\"},{\"date\":{\"ms\":1588436697},\"sensor\":\"22.10\"},{\"date\":{\"ms\":1588436701},\"sensor\":\"22.27\"},{\"date\":{\"ms\":1588436705},\"sensor\":\"22.16\"},{\"date\":{\"ms\":1588436709},\"sensor\":\"22.27\"},{\"date\":{\"ms\":1588436713},\"sensor\":\"22.19\"},{\"date\":{\"ms\":1588436717},\"sensor\":\"22.27\"},{\"date\":{\"ms\":1588436721},\"sensor\":\"22.23\"},{\"date\":{\"ms\":1588436725},\"sensor\":\"22.29\"},{\"date\":{\"ms\":1588436729},\"sensor\":\"22.19\"},{\"date\":{\"ms\":1588436733},\"sensor\":\"22.05\"}] >> >\r\n>" Unable to connect! your data:undefined
And basically it does this until I stop and start the nodejs app again.
Thank you.
-
oh oops you're right, unfortunately that didn't solve my problem. I'm making a better post about it on the github commit.
Thank you.