-
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.
[{"id":"76f88a3c.99fe04","type":"tab","label":"Flow 2"},{"id":"6892e216.8f6d2c","type":"debug","z":"76f88a3c.99fe04","name":"","active":true,"console":"false","complete":"payload","x":340,"y":60,"wires":[]},{"id":"503cfb7e.f411c4","type":"mqtt in","z":"76f88a3c.99fe04","name":"","topic":"#","qos":"2","broker":"98edcbd7.d02a98","x":110,"y":60,"wires":[["6892e216.8f6d2c"]]},{"id":"98edcbd7.d02a98","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]
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
-
Ok good point. But I think you will find that your phone doesn't advertise itself continuously like the Puck does. My android phone, for example, only advertises when the bluetooth settings page is open. So the iPhone maybe isn't hiding, per se, but is just not advertising. Another possible issue as I also have with my phone, is it doesn't advertise as a BLE device. EspruinoHub for example doesn't see it. But from my PC I was able to add the phone as a Bluetooth device and send files and play music from it. Maybe you could do it in reverse and detect the Puck proximity from the phone, and then take some action.
-
I have tried broadcasting ('advertising') using example code from this thread and it works great.
setInterval(function() { NRF.setAdvertising({ 0x1809 : [Math.round(E.getTemperature())] }); }, 1000);
on the monitoring end the EspruinoHub software works well on the RPi. The temperature in this case gets published by the hub to the local mosquitto MQTT broker where it can be subscribed to by any MQTT client. For example the client on the RPi (change the MAC address to yours)
mosquitto_sub -v -t /ble/advertise/c7:6e:71:dd:ee:ff/temp
or
mosquitto_sub -v -t /ble/advertise/# | grep temp
Note that the hub only publishes when the temp value has changed, or every 60 seconds.
This is what the EspruinoHub displays while it is running in the foreground and while the Puck is advertising the temperature
Config loaded MQTT Connected <HTTPProxy> Bleno State poweredOn <HTTPProxy> Bleno.startAdvertising Success <HTTPProxy> Bleno.setServices Success Scanning started... Thu Dec 22 2016 09:30:53 GMT-0500 (EST) eb:83:4c:dd:ee:ff - Puck.js eeff (RSSI -63) 1809 => {"temp":19}
-
-
This happened to me just a little while ago. Running 1v90.9. I think my device was idle. But I don't remember what it had exactly. I connected via BLE and uploaded code and got an error "processing BLE task, queueing task" or something like that. Tried upload again after a minute or so. Frozen, no response. Battery bump. Then this:
_____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |_____|___| _|_| |___|_|_|_|___| |_| http://espruino.com 1v90.9 Copyright 2016 G.Williams Uncaught SyntaxError: Got ?[255] expected EOF at line 1 col 1 ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ... ^ > Disconnected
So it looks like the same problem more or less. reset() worked but save() caused a restart. I reflashed with 1v90.9 but no change. I found @Gordon 's recent post and applied 1v90.12. Well the weird messages and characters are gone, and I can load a program and it runs, but save() still causes a restart. So we're not quite there yet. But I'm chill. Happy holidays everyone!
-
-
I think your phone would have to be 'advertising' in order to be 'discoverable' for Puck to be able to detect it and evaluate the RSSI. The Tessel 2 has native WiFi. Another option, perhaps, is to give your phone a static IP on your WiFi LAN, and then Tessel can detect your phone's 'arrival' and control the bulbs. Just thinking out loud.
-
-
At least if you're in the USA. $0.44 each delivered (Amazon Prime). 10 year shelf life. I have 5 Pucks to feed. :(
https://www.amazon.com/gp/product/B008XBK7PG/ref=oh_aui_detailpage_o04_s01?ie=UTF8&psc=1
-
@Fabio978 I get something similar. I believe it's because toFixed() returns a string and the temperature value is supposed to be 16 bit floating point number. The characters in the string that end up being read as a sint16 and converted to floating point for display just happen to represent 143.85. I tried just rounding the temperature down to an integer but that doesn't work at all. The battery works fine because it's being read as a byte, with a valid range of 0 to 100.
-
The firmware works and it cleans up the error reporting, but doesn't seem to improve my results very much. I wrapped a 30 second interval and some counters around the remote button code and let it run for awhile. Consistently the success rate is 59% to 65%. It's about the same whether or not the IDE is connected. I also noticed that after awhile, the remote button Puck stops transmitting entirely and I have to pop the battery to get it restarted. So maybe something in the code doesn't like being executed every 30 seconds. In any case I'll fiddle around with it for the next few weeks. Happy holidays!
-
-
Yes I should have mentioned that 1v90.5 is running on the 'remote button' puck and 1v90 on the target.
I'll have to try and characterize results when connected from the IDE and not. I'm trying several examples including 'ble_simple_uart' and results aren't much different.
I've also seen situations where the 'get service' simply doesn't return. Re-entering the function causes an error saying a BLE request is in progress or something like that. At this point I have to do a reset() and load() to recover.
-
I tweaked some puck example code from various places to make a remote button for a puck. A silly use case but a chance to try out connecting to a puck. This is the target device. A button press turns the blinking on and off and changes the color.
var on = false; var stop = 0; var c = 1; function startBlink() { on = false; if (stop !== 0) { clearInterval(stop); stop = 0; LED1.write(0); LED2.write(0); LED3.write(0); } else { switch (c) { case 1: led = LED1; //print("red"); c = 2; break; case 2: led = LED2; //print("green"); c = 3; break; case 3: led = LED3; //print("blue"); c = 1; break; } stop = setInterval(function() { on = !on; led.write(on); }, 500); } } setWatch(startBlink, BTN, { repeat:true, edge:'rising', debounce : 20 });
And this is the remote button code. It will try and connect to the target and issue a command that simulates pressing the button.
function flashLed(led) { flashLed.count = 0; flashLed.h = setInterval(function() { if (flashLed.count++ == 6) { led.write(0); clearInterval(flashLed.h); flashLed.count = 0; } else { led.write(flashLed.on = !flashLed.on); } }, 500); } function sendCmd() { var name = "Puck.js d958"; // change me to your target puck's name var gatt = null; console.log("searching for " + name); NRF.requestDevice( { filters: [ { namePrefix: name } //{ namePrefix: 'EspruinoHub' } ] } ).then(function(dev) { console.log("device found", dev); return dev.gatt.connect(); } ).then(function(conn) { gatt = conn; console.log("connected", conn); return conn.getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e"); } ).then(function(s) { console.log("service found", s); return s.getCharacteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e"); } ).then(function(c) { console.log("characteristic found", c); c.writeValue("startBlink()\n"); } ).then(function() { gatt.disconnect(); console.log("disconnected"); } ).then(function() { console.log("success!"); flashLed(LED2); } ).catch(function(e) { console.log( "catch caught an error!"); console.log( "error:", e ); if (gatt !== null) { gatt.disconnect(); console.log("disconnected"); } flashLed(LED1); console.log("all done"); } ).catch(function(e) { console.log( "catch caught another error!"); console.log( "error:", e ); flashLed(LED1); console.log("all done"); } ); } setWatch(sendCmd, "D0", { repeat:true, edge:'rising', debounce : 50 });
It works about half the time. But very often I get the following error output. I have tried to look up the BLE error code but I can't find anything on it.
searching for Puck.js d958 device found BluetoothDevice { "id": "ca:78:ab:df:d9:58 random", "rssi": -57, "services": [ ], "data": new ArrayBuffer([2, 1, 5, 13, 9, 80, 117, 99, 107, 46, 106, 115, 32, 100, 57, 53, 56]), "name": "Puck.js d958" } connected BluetoothRemoteGATTServer { "device": BluetoothDevice { "id": "ca:78:ab:df:d9:58 random", "rssi": -57, "services": [ ], "data": new ArrayBuffer([2, 1, 5, 13, 9, 80, 117, 99, 107, 46, 106, 115, 32, 100, 57, 53, 56]), "name": "Puck.js d958", "gatt": ... }, "connected": true } catch caught an error! error: Error { "msg": "Got BLE error code 12290", "type": "Error", "stack": " at line 35 col 75\n...5a3-f393-e0a9-e50e24dcca9e\");\n ^\nin function called from system\n" } catch caught another error! error: Error { "msg": "Got BLE error code 8", "type": "Error", "stack": " at line 57 col 25\n gatt.disconnect();\n ^\nin function called from system\n" } all done >
This is the interesting bit:
error: Error {
"msg": "Got BLE error code 12290",
"type": "Error",
"stack": " at line 35 col 75\n...5a3-f393-e0a9-e50e24dcca9e\");\n ^\nin function called from system\n"The puck appears to connect ok but then it looks like the code blows up attempting to get the service. Like I said this happens about half the time. When it works properly it works very well.
Clearly I am not doing something entirely right here. Any thoughts would be appreciated.
-
-
I like Odroids because they are fast and cheap, though not as cheap as the RPi. I mostly just followed the directions for installing the hub on a RPi. Everything was looking good on the XU4 but when I tried to start the hub I got a screen full of errors.
So I said 'ok', went and dusted off a RPi 2 and loaded everything up there. This time the startup was fine and the EspruinoHub was working fine.
Went back to the XU4 and looked at those errors again. Despite looking like a crash with a bunch of uncaught errors, the basic problem really was 'unable to connect to mqtt', and 'not authorized'. The problem was that unlike the RPi, the mosquitto server for Ubuntu by default does not allow anonymous connections. So I changed the config to allow anonymous and now the hub works perfectly.
Tl;Dr - EspruinoHub works great on Odroid and Ubuntu. Just need to allow anonymous to mosquitto
-
-
@ChristianW, there's no code. It's simply the EspruinoHub running from the start script in the foreground and outputting to standard out.
The hub properly detects my pucks (and my fitbit) and refreshes rssi every second. The hub is advertising itself also so I just tried to connect from my Galaxy S6 and boom, the errors.
As I mentioned, maybe I wasn't supposed to do that :)
Interestingly the EspruinoHub that I set up on my Odroid XU4 doesn't crash when I do the same thing. The connection still fails but no crash.
-
This happens if I try and connect to it via Bluetooth from my Android phone. Maybe I'm not supposed to do that :)
noble: unknown peripheral 746c793faf24 connected! buffer.js:491 length += buf.length; ^ TypeError: Cannot read property 'length' of undefined at Function.Buffer.concat (buffer.js:491:20) at Smp.handlePairingConfirm (/home/pi/EspruinoHub/node_modules/noble/lib/hci-socket/smp.js:93:21) at Smp.onAclStreamData (/home/pi/EspruinoHub/node_modules/noble/lib/hci-socket/smp.js:59:10) at emit (events.js:117:20) at AclStream.push (/home/pi/EspruinoHub/node_modules/noble/lib/hci-socket/acl-stream.js:35:10) at NobleBindings.onAclDataPkt (/home/pi/EspruinoHub/node_modules/noble/lib/hci-socket/bindings.js:272:15) at emit (events.js:106:17) at Hci.onSocketData (/home/pi/EspruinoHub/node_modules/noble/lib/hci-socket/hci.js:473:14) at BluetoothHciSocket.emit (events.js:95:17)
EspruinoHub on RPi 2
Raspbian GNU/Linux 8 (jessie)
node --version v0.10.29 -
Well it worked, which is good, but I'm still confused, which is normal. After I ran zadig and replaced the driver on the BLE USB device, the bluetooth radio devices in device manager disappeared to be replaced by a generic USB serial bus device. Ran the native web IDE and was able to list all my pucks and connect to a few of them and run commands. As far as Windows bluetooth it still appears to be working, though all Windows can see on bluetooth is a Samsung TV in the other room. It does not list the pucks. On android the pucks do show up on a bluetooth scan.
-
-
-
I have a similar setup (Win 7 x64) and I am seeing very similar results where windows can see the puck via BLE but the native application does not. The console log shows these errors at the beginning:
We have chrome.serial - not using 'serialport' module
'noble' module couldn't be loaded, no node.js Bluetooth Low Energy Error: LIBUSB_ERROR_NOT_SUPPORTED
'winnus' module not found, no Windows Bluetooth Low Energy Error: The specified module could not be found. \?\C:\Users\t44a8l2\AppData\Local\Temp\nw10628_25245\node_modules\winnus\build\Release\winnus.nodAnd then later:
Connecting...
Set Slow Write = true
BT> ERROR: NotFoundError: User cancelled the requestDevice() chooser.
ERROR: [notify_error] Connection Failed.
Connection Failed.
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