Suggestion for program #2666
Replies: 17 comments
-
Posted at 2018-08-05 by Robin Sun 2018.08.05 Hello @terrence7 Does this excellent video tutorial provide the insight you seek? Door Controlled Light with Puck.js See 'Tutorials' (sixth heading down page) listed on Puck page documentation other forum posts that might provide some insight
How can I get the rotation change by Magnet xyz value ? Using a 3-Axis Magnetometer as a compass Is the Magnetometer a MAX3110 or a MAG3110? EDIT
Puck.js Bluetooth with the Graphical Editor
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-05 by Terrence7 Robin, thank you for those links. I will start reading and watching them. I can figure out how to take a reading on the mag or accelerometer. Where I am having trouble is the BLE part of the equation. I just want to send a signal, do I have to do advertising and or GATT services, or can I just send a signal without all of the BLE ceremony? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-05 by @allObjects @terrence7, when reading movements from accelerometer, you modify the puck's advertisement, and go back to normal advertisement a while later. Periodically, on another puck or on Pi you check who 'is out there' by scanning for advertisements and filter the one you are interested in. You always keep the last one for comparison with the present one to determine when the movement started respectively has stopped. The change - either begin or ended - you publish to the IoT Azure Hub. Whether you can do all in graphical editor - blockly - or or not, I don't know. But doing it in JS may even be simpler. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-06 by Terrence7 @allObjects Thanks for you helpful comments. Any thought on this comment?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-06 by @allObjects Advertising is the way puck sends simplest signal. With suggested approach you do not even enter bidirectional communication. Take a look at Advertising. In the example there, puck changes advertisement every button press: a value is incremented and this value is advertised. On the receiving - or interested - side, a scan for devices is issued, which will pick-up the advertisement. That's all there is. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-06 by @gfwilliams As @allObjects says, Advertising is what you want. It's only in one direction so it's not guaranteed that you'll receive every advertising packet. What I usually say is to transmit a number all the time, and to then just increment that number when something happens. It's then easy to detect on your IoT hub. This might help you out quite a bit as it uses sending a button press as an example: BLE Advertising with Node.js/Python/C#/Android I should add that Puck.js doesn't have an accelerometer - it's a magnetometer (effectively a 3D compass). It's still pretty easy to use it to detect movement though as any rotation would change the compass reading. There's a post here: http://forum.espruino.com/conversations/301185/ But basically you want some code like:
But I'm afraid at the moment that's not something that you could do with the graphical editor - it'd have to be JS. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-07 by Terrence7 @allObjects, @gfwilliams Thank you for your great responses. I have settled on using the light sensor, as the puck will be inside the tub, and will get flooded with light when he opens the lid. Problem is distance. Gordon, how far should I expect a puck to Rpi to be able to communicate?
Isn't that going to burn up the battery? I would like to get a couple of months battery out of a once a day event advert. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-07 by @gfwilliams
In my house I manage around 10M including two floors and a brick wall pretty reliably. You can get more in free air, but it's the brick walls that really impact the transmission.
Surprisingly not that much. The Puck has to keep broadcasting so it can be connected to - so you're not adding more power usage over what it's doing already. If you leave it as-is you should get at least 6 months out of it. You might want to increase the transmit power with While you can use It might be worth doing |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-08 by Terrence7 Here is my proposed code, do you have any suggestions?
Thank you.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-08 by @gfwilliams I'd do But yes, that'd work fine - although I'd still recommend that you use the counter method if you want to be sure you don't miss things happening.
I think it is an output by default - just stick
Correct, yes. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-09 by Terrence7
My IOT hub will be a rpi3. I plan on capturing the battery reading when the lid has been opened, and thus will only be one hit a day. In my else statement I send a 0, though you are recommending a count. I don't plan on doing anything with the count, but I am interested in your suggestion, please tell me more about how this will help. (a bit slow here :) ) Here is the current state of my code:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-09 by @allObjects ...you can keep/use the count to detect that the advertisement has changed... because I think you want to advertise over a certain period of time... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-09 by @gfwilliams Advertising only sends data in one direction so it's not guaranteed that you'll receive every advertising packet that is sent. What I usually say is to transmit a number all the time, and to then just increment that number when something happens. It's then easy to detect on your IoT hub even if you miss a few packets.
I think you think that This might help a bit: http://www.espruino.com/About+Bluetooth+LE So the code above will work great, but you'll keep receiving advertising packets on your Pi 3 all the time. Actually sending advertising data doesn't actually use that much power though - your device will still last for months on a battery. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-09 by Terrence7 Yes, I was under the impression it would send it just when I ask it to.
I have read over that page, all good info, but being new the concepts take a bit to sink in. Q & A really helps. Thank you for your clarifications. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-09 by @gfwilliams
correct, yes...
Not really - that's just how often it calls your The actual advertising interval is an argument to setAdvertising: http://www.espruino.com/Reference#l_NRF_setAdvertising For instance
Yes and no. Yes, I'd say set In terms of advertising, I'd set that to 10 seconds absolute maximum. Honestly once you get past once every few seconds you're making pretty small improvements to battery life. It's still going to last a year or so. I should add that Advertising sends data on 3 frequency bands, each in turn. However a lot of bluetooth radios only listen for advertising on one channel at once - so they'll only get every third transmission even if there is no interference at all. It really pays to make sure you send a few more packets than you absolutely need, especially as the cost is so low. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-13 by Terrence7 Gordon, thanks for your incredible support. I am now looking at BLE coding on RPI to pick up the adverts. I hope you might help me in that area once I get over there. .net / asp.net / sql server etc dev. This \IOT js dev is a new area for me and its taking a bit to get my head around it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-13 by @gfwilliams For the RPi stuff, check out: http://www.espruino.com/Puck.js+Advertising Either the Node.js or Python code should work pretty well for you. It deals mainly with getting manufacturer data rather than service data, but you could swap the Puck over to advertise that pretty easily or you could modify the code on the Pi - once you have something that gets advertisements from that link, tweaking it to read the service data field rather than the manufacturer one is nice and easy |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-08-05 by Terrence7
I plan on creating a notice to inform me when my son feeds the dogs.
I am going to Velcro the Puck in the round screw in lid to the dog food bucket.
When he turns the lid to open it up, the accelerometer will sense movement and send out a message (battery level).
My Ras Pi will be listening for that message and when it receives it, it will send a message to my Azure IOT Hub. ( can handle the raspberry pi code)
I wonder if you could help me on the how I might go about programming the Puck to send a message when the accelerometer senses movement?
Is it possible with the graphical designer?
Thank you for any coding you can help me with so this doesn't take me a month to figure out.
Beta Was this translation helpful? Give feedback.
All reactions