Looking For Sample Code - button presses and sensors #1226
Replies: 4 comments
-
Posted at 2020-01-28 by Robin Tue 2020.01.28 @user108908, which specific sensors did you have in mind? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-01-28 by user108908 Thanks - yes, I've poked around in there... not yet sure how to weave it all together and suspect the code is out there somewhere. Forgot to mention I have gotten EspurinoHub installed, which appears to aggregate some of the advertising and post results to MQTT. I'd like to get readings from the magnetometer (open/close door), temp and light sensor, as well as battery level. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-01-29 by Robin Tue 2020.01.28
So @user108908, is it possible that what is being attempted has started with a bit of overkill with a not so suitable starter example? . . . or . . . is the task at hand a question for where to decode the sensor data, rather than/or how to interface with MQTT and EspruinoHUB? I grabbed this easier to follow example Puck Detecting Movement from the 'Tips and Tricks' page: Obtaining the current battery level: "You can use Puck.mag() to return one magnetometer reading (with x, y, and z axes)" code snippet from: As the Tutorials section is directed at providing a solution map for others to follow to reach the same proven presentation, *see beneath heading in the specific 'Tutorials' posting pane on the right hand side,* "Post any tutorials/examples for Espruino here!" that a better thread section might provide better visibility for what is desired here? > For: @gordon This post most likely would benefit user108908 if it were posted under: Home >> Official Espruino Boards >> Puck.js or Interfacing, perhaps?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-01-29 by @gfwilliams Hi! It's great that you've got EspruinoHub set up - that should make things way easier. There's the example of button presses on https://www.espruino.com/BLE+Node-RED:
That uses
So for instance if you want to show battery as well as button presses, you could do:
You can also make your own by modifying EspruinoHub at https://github.com/espruino/EspruinoHub/blob/master/lib/attributes.js#L38 There's another option mentioned in https://github.com/espruino/EspruinoHub#advertising too, which is actually much nicer and tidier - you advertise JSON:
The only thing to watch out for there is you don't want your JSON string to get too long, since there's a ~20 byte limit on the size of the data you can advertise. As an example though, if you want to broadcast door openings then you can look at the code to measure when the door is open at http://www.espruino.com/Puck.js+Door+Light
And where you know the door has changed state then you just update the information you advertise with
Then on MQTT you should see the following:
Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-01-28 by user108908
Hi All,
I'm looking to use a few puck-js units in my home automation.
I've implemented this guide for button control and led control:
https://www.espruino.com/BLE+Node-RED
But I'm unsure of how to weave in the other sensors. I've spend 45 minutes or so looking, but haven't been able to find some code I can use.
Can someone point me to an example that I can build off of? I'm a beginning JS coder.
Beta Was this translation helpful? Give feedback.
All reactions