Puck.js with Node-RED on Raspberry Pi #1829
Replies: 12 comments
-
Posted at 2016-12-24 by dklinkman This comment http://forum.espruino.com/comments/13381021/ may answer some of your questions. If you point your browser to Node-RED on your RPi3, you can set up an MQTT input node that will read those topics and take whatever actions you want. For example, this is a NR flow you can import that simply reports MQTT messages to the debug tab.
A more sophisticated example might look for the temp topic advertising device temperature and update a gauge node that would be dsiplayed on the Node-RED UI |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-24 by badryan I think that's exactly what I was after. I was confused whether I would have to write some code in NRF.setAdvertising or whether the out-of-the-box behaviour was sending a summary of all sensors. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-24 by AntiCat Retrieving sensor data works flawlessly.
However, transmitting commands always fails:
Does any one know what could cause this issue? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-24 by dklinkman Are you sure you disconnected the IDE from the puck before your attempt? I can't get mine to work at all but it's a different set of errors. Another problem is I believe your string is too long. I believe 20 characters is the limit. You could type this function into your puck (remember to disconnect after):
and then change your mqtt message to "x();\n" just to try it out |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-25 by dklinkman here's a short bash script that will portion the message into multiple messages. i actually can't test this properly since my hub is messed up but hopefully you get the idea.
for example (assuming the script above is named 'script'):
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-25 by AntiCat I've somehow missed the 20 character limit on commands. That could be the source of my issue. I'll try it as soon as possible. @dklinkman you mentioned various other errors. I initially had different errors also. Then I switched to v90.12 (http://forum.espruino.com/conversations/297615/) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-25 by dklinkman @AnticaT I've got v90.12 also but I'm still having problems. There's something going on inside EspruinoHub with a function within noble called discoverAllServicesAndCharacteristics(). It should return very quickly with arrays of services and characteristics, but most of the time it doesn't and the connect process times out after 4 seconds. At the puck end I see a connection followed by an immediate disconnect. It shouldn't disconnect and that's probably why discoverAllServicesAndCharacteristics() doesn't pass back any data. These are the messages:
The second error is because the timeout is trying to disconnect but the device is already disconnected. I wrote my own javascript that uses noble and runs at the command line to do similar and I get the same results. Oddly if I do an explicit connect followed only by an explicit disconnect, all of the above works but only one time. It's maddening. In my javascript I changed the logic to do separate discover services and discover characteristics and now that part is working better. I also tweaked the logic to allow writing up to 60 characters vs 20. I might try similar changes to the EspruinoHub logic and see if that helps at all. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-27 by dklinkman I have a fork of the EspruinoHub that fixes the problems I have been experiencing. I think this is still related to this thread since mqtt is integral to node-red and being able to initiate and respond to events. https://github.com/dklinkman/EspruinoHub I had trouble connecting to the puck reliably, initially, and I was able to figure out over time that this was related to something in noble. But short of it is that I changed the logic in EspruinoHub and it's a lot more reliable now. At least for me. I also added logic so the mqtt message text sent to the puck was no longer limited to just 20 bytes. So something like this works now on the RPi:
even while the text is > 20 chars. Note also the RPi /bin/bash $'...' syntax. Required. Reading a service now works. There was a bug causing a crash. For example the following now reads the puck name:
and outputs the result when appropriately subscribed to mosquitto_sub -v -t /ble/data/#
I also fixed a problem where the device discovery would stop after an mqtt event resulting in a watchdog timeout and restart but only by the shell script. Now the discovery restart happens more inline. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-01 by AntiCat @dklinkman Thank you for publishing your changes. Unfortunately, it has no effect on my issue. Since my error |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-01 by dklinkman That's unfortunate. Is the output the same as your original post above? All I can say is it's working great here. RPi3, fresh install of latest OS, updated and upgraded all packages, followed the instructions for building the hub. Of course it didn't work for me originally but since I modified the hub code it's fine. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-02 by AntiCat I bought a RPi3 today. Identical software (same SDCard) as earlier works! So the issue must be related to my RPi2+BLE dongle. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-02 by dklinkman Good news! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-12-23 by badryan
I've followed the quickstart example on my Raspberry Pi v3 and can easily recognise my Puck along with its rssi value. According to the documentation of the EspruinoHub there should be a topic /ble/advertise/DEVICE/SERVICE, but I don't get to see any information. Do I have to write code on the Puck or modify the EspruinoHub to retrieve any sensor data, or should these come automatically using defaults?
Beta Was this translation helpful? Give feedback.
All reactions