Git Product home page Git Product logo

espruinohub's Introduction

Espruino JavaScript for Microcontrollers

 _____                 _
|   __|___ ___ ___ _ _|_|___ ___
|   __|_ -| . |  _| | | |   | . |
|_____|___|  _|_| |___|_|_|_|___|
          |_|

https://www.espruino.com           Join the chat at https://gitter.im/espruino/Espruino

About

Espruino is a JavaScript interpreter for microcontrollers. It is designed for devices with as little as 128kB Flash and 8kB RAM.

Please support Espruino by ordering one of our official boards or donating.

Documentation

If you have an Espruino board, please read the Quick Start Guide first.

Browse the Espruino Website (try using search in the top right), and read the FAQ.

There's also a Reference for JavaScript commands as well as Tutorials. However the documentation on the Espruino website will match the version available for download but not the latest version on GitHub.

Builds for the Espruino Board and Pico Board (built automatically for each Git commit) are available from here.

Other documentation of use is:

Support / Bugs

First, please try and check that your problem hasn't already been found or covered on our forum.

Submit bugs with clear steps to reproduce them: a small test case (not your whole program), and an actual and expected result. If you can't come up with these, please post on the forum first as it may just be something in your code that we can help out with.

Work on Espruino is supported by sales of our boards.

If your board isn't made by us but came pre-installed with Espruino then you should contact the manufacturers.

We try and support users of the boards we sell, but if you bought a non-official board your issue may not get addressed. In this case, please consider donating to help cover the time it takes to fix problems (even so, we can't guarantee to fix every problem).

License

Please see the LICENSE file.

Building

Check out the page on building Espruino.

Testing

There are a bunch of tests in the tests directory. See tests/README.md for examples on how to run them.

Current State

The officially supported boards are the best supported. They come pre-installed with Espruino and you are able to easily download and flash the latest versions of Espruino to them.

While Espruino can run on other boards, we make no money from them and so cannot afford to test, fix or support the firmware on them. We're dependent on the community.

You can download binaries from https://www.espruino.com/Download.

If you are a board manufacturer interested in getting your board officially supported, please check out this page.

For a list of supported boards, please see the boards folder.

Main supported platforms are:

  • STM32 (F1, F3, F4, L4)
  • nRF52
  • nRF51
  • ESP8266
  • ESP32
  • Linux

Espruino has been ported to other boards and platforms (such as EFM32 and SAMD), but these have a habit of being contributed and then never maintained. All boards that this has happened to reside in the UNMAINTAINED_BOARDS branch.

Modification

Check out the documentation on the build process first - this should clear up a lot of potential questions about the Espruino architecture.

Please see CONTRIBUTING.md for some hints about code style/etc.

You can auto-build documentation for all source files - see doxygen/README.md

Any more questions? ask on the forum.

Porting to new devices

If you're using an existing architecture everything can be done from boards/BOARDNAME.py. See a similar board's .py file as an example.

However for a new architecture there are a bunch of different files to modify.

  • boards/*.py files describe the CPU, available pins, and connections - so the relevant linker script, headers + docs can be created
  • boards/pins/*.csv are copies of the 'pin definitions' table in the chip's datasheet. They are read in for STM32 chips by the boards/*.py files, but they are not required - see boards/MICROBIT.py for an example.
  • Global build options are handled in Makefile
  • The make directory contains arch-specific Makefile fragments
  • Extra libraries like USB/LCD/filesystem are in Makefile
  • Processor-specific code in targets/ARCH - eg. targets/stm32, targets/linux
  • Processor-specific libs (like the SDK) in targetlibs/ARCH
  • src/jshardware.h is effectively a simple abstraction layer for SPI/I2C/etc, which should be implemented in targets/ARCH/jshardware.c

Adding libraries

  • Create jswrap_mylib.c/h in libs/
  • Create library functions (see examples in other jswrap files, also the comments in scripts/common.py)

See libs/README.md for a short tutorial on how to add your own libraries.

Using Espruino in your Projects

If you're using Espruino for your own personal projects - go ahead, we hope you have fun - and please let us know what you do with it on https://www.espruino.com/Forum!

If you're planning on selling the Espruino software on your own board, please:

  • Let us know, we might be able to help.
  • Read the terms of the MPLv2 Licence that Espruino is distributed under, and make sure you comply with it
  • MPLv2 dictates that any files that you modify must be made available in source form. New files that you create don't need to be made available (although we'd encourage it!)
  • You won't be able to call your board an 'Espruino' board unless it's agreed with us (we own the trademark)
  • You must explain clearly in your documentation that your device uses Espruino internally
  • Please don't fork Espruino - improvements get very hard to share, and in the long run everyone loses.
  • Please give something back to the project - be it code improvements, documentation or support.

We spend a lot of time supporting Espruino on the forums, but can only do so because we make money from the sales of Espruino boards. If your users request support from us then we have absolutely no obligation to help them. However, we'll be a lot more motivated if you're actively helping to improve Espruino for all its users (not just your own).

espruinohub's People

Contributors

adboomlodestar avatar arnooooo avatar bettse avatar dependabot[bot] avatar dklinkman avatar ehershey avatar g1k avatar gfwilliams avatar grumpymeow avatar jcheger avatar jjguti avatar jjok avatar kuli avatar otbe avatar palortoff avatar rmcubed avatar rsmeral avatar sarfata avatar the1laz avatar tomgidden avatar twocolors avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

espruinohub's Issues

Crash on start

I think I have a fix for this. It could be due to code running on my puck.js.

Output when I run "./start.sh" from current master branch:

./start.sh: line 5: setterm: command not found
readlink: illegal option -- f
usage: readlink [-n] [file ...]
sudo: setcap: command not found
Starting without Bleno (GATT Server)
[Config] Config config.json loaded
[HTTPProxy] config.http_proxy=false, not enabling Bleno/Proxy
[MQTT] Connecting...
[HTTP] Server is listening on http://localhost:1888
[HTTP] www directory found at /Users/ernie/git/EspruinoHub/www. Web server at http://localhost:1888
[History] history_path value is empty, thus not providing history.
[MQTT] Connected
[Discover] Re-sending presence status of known devices
[Discover] Noble StateChange: poweredOn
[Discover] Starting scan...
[Discover] Scanning started.
FATAL ERROR:  Cannot read property 'forEach' of undefined
 1: 0x1041a3db8 node::Abort() [/opt/homebrew/opt/node.js/bin/node]
 2: 0x1041a3f3c std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string<std::nullptr_t>(char const*) [/opt/homebrew/opt/node.js/bin/node]
 3: 0x1041a3dd0 node::OnFatalError(char const*, char const*) [/opt/homebrew/opt/node.js/bin/node]
 4: 0x10417d9e4 napi_open_callback_scope [/opt/homebrew/opt/node.js/bin/node]
 5: 0x1088f4c98 Napi::Error::~Error() [/Users/ernie/git/EspruinoHub/node_modules/@abandonware/noble/lib/mac/native/binding.node]
 6: 0x108903bc4 ThreadSafeCallback::Impl::static_async_callback(uv_async_s*) [/Users/ernie/git/EspruinoHub/node_modules/@abandonware/noble/lib/mac/native/binding.node]
 7: 0x104a0e2ac uv__async_io [/opt/homebrew/opt/node.js/bin/node]
 8: 0x104a1de58 uv__io_poll [/opt/homebrew/opt/node.js/bin/node]
 9: 0x104a0e6cc uv_run [/opt/homebrew/opt/node.js/bin/node]
10: 0x1040fd15c node::SpinEventLoop(node::Environment*) [/opt/homebrew/opt/node.js/bin/node]
11: 0x1041d8bc8 node::NodeMainInstance::Run(node::EnvSerializeInfo const*) [/opt/homebrew/opt/node.js/bin/node]
12: 0x10417c464 node::Start(int, char**) [/opt/homebrew/opt/node.js/bin/node]
13: 0x18b559450 start [/usr/lib/system/libdyld.dylib]
./start.sh: line 19: 74087 Abort trap: 6           node index.js

Using multiple BLE dongles?

I want to run node-red and espruinoHub on the same machine, with this I have run into an issue.
As soon as espruinoHub makes a connection the ble scanner in node-red stopps, and wont get any new messages until espruinoHub has closed it's connection and I restart node-red.

To work around this my first thought is to use two BLE dongles on the machine.
In this case its a RaspberryPi 4, so the internal BLE is HCI0, thats what node-red and noble defaults to.

So now I'm trying to make espruinoHub use HCI1 instead, but how ever I try this I cant get it to work.

In noble I found that setting NOBLE_HCI_DEVICE_ID=1 should make noble use HCI1.
But for what ever reason it either does not do this, or it does and it still conflicts with node-red.

The bigger picture here is that we use node-red to collect data from espruino devices, works great. And it would be amazing to be able to run espruinoHub on the same machine to be able to remotely change the JS code on devices.

HomeAssistant doesn't work with `known_devices`

Discussed at #79

Devices in known_devices don't have their data appearing properly in home assistant.

The fix should:

  • Name devices according to their known_devices name
  • Respond to /ble/json/devicename not /ble/json/de:vi:ce:ad:dr:es:ss

Subscribe from other broker - Home Assistant

I'm a novice at best, so if I'm asking poor questions, I apologize. I got EspruinoHub up and running in a Raspberry Pi Zero W today. It is recognizing bluetooth devices and I can view the http site to track status, etc. I have two questions.

  1. My goal is to connect this to my Home Assistant instance (separate computer that has its own mqtt broker) to track presence of specific devices. I just want to make sure that I understand what EspruinoHub is doing "out of the box". Is it publishing topics (ble/presence/DEVICE) to the broker specified in the config.json?

  2. How are you handling bluetooth devices that advertise spoofed mac addresses (for security)? If I hard code the correct mac address in config.json, will EspruinoHub look specifically for that device or only apply the name when it receives something from that mac address? I ask because your examples confused me. I expected the known devices in config.json to be something more along the lines of "jims_phone", "sallys_tablet", not specific rooms where the Pi is located.

Again, sorry for the basic questions. I just need to determine next steps now that EspruinoHub is up and running. I'm brand new to ble and mqtt.

Post-connection request for servics can get into loop

If a connection fails before the list of services is acquired, it is possible to get into an infinite loop looking for services. The only cure seems to be to restart EspruinoHub.

A desirable behaviour might be to force close the connection if more than a certain number of service requests fail?

No UI elements in node red

Hi i installed the hub and getting the information from BLE works fine (trying to work with my new puckjs). But i cannot see the UI nodes. Restarting didn´t work. Any idea why ui nodes are missing?

Parsing JSON failure. Porbably extra comma?

The installation was a breeze for me. Here is my platform setup.

  • Hardware: Raspberry Pi 3 B
  • Distribution: Raspbian GNU/Linux 10 (buster)

I have followed exactly the steps under the installation section. Installation was successful.

The node-red server is up and running at the port 1880 as expected.

However, when I run the start.sh script, I see an error at the very beginning of the log below:

[Config] Error parsing config.json: SyntaxError: Unexpected token } in JSON at position 2973
[MQTT] Connecting...
[HTTPProxy] config.http_proxy=false, not enabling Bleno/Proxy
[HTTP] No http_port in config. Not enabling web server
[History] history_path value is empty, thus not providing history.
[MQTT] Connected
[Discover] Re-sending presence status of known devices
[Discover] Noble StateChange: poweredOn
[Discover] Starting scan...
[Discover] Scanning started.

Fri Mar 26 2021 14:57:56 GMT-0400 (Eastern Daylight Time)

04:52:c7:34:b4:d5 - Bose QuietComfort 35 (RSSI -92)
0a:8a:c0:53:5e:4c - ? (RSSI -90)
25:b8:14:8a:9a:e7 - ? (RSSI -93)
42:cb:f2:74:3e:c3 - ? (RSSI -48)
43:c6:10:ba:7b:1e - ? (RSSI -84)
44:49:f7:b7:8c:c0 - ? (RSSI -94)
4b:83:1d:91:50:e3 - ? (RSSI -72)
4c:29:48:1c:db:97 - ? (RSSI -90)
  fd6f => [181,106,237,62,240,80,10,31,33,118,47,121,51,118,188,198,7,97,230,183]
54:76:46:ac:29:e5 - ? (RSSI -68)
67:b8:d3:50:33:b7 - ? (RSSI -61)
68:ac:6a:9e:80:23 - ? (RSSI -78)
6c:2b:dc:1b:f6:39 - ? (RSSI -68)
73:0a:d4:e1:88:67 - ? (RSSI -90)
7b:bf:93:e1:60:3b - ? (RSSI -55)
f8:72:9e:27:2c:16 - LHB-197C2AD7 (RSSI -91)
[CONNECT] Connections [] IDLE

I deleted the ending comma from this line, and tried again. Things were working and the EspruinoHub is accessible from port 1880.

Something has changed on the backend for EspruinoHub?

`VM11:1

GET https://www.espruino.com/serial/ports 404 (Not Found)

index.js:92927 /serial/ports doesn't exist - disabling WebSocket support`

When I run EspruinoHub on my raspberry pi and access the Top Left

image

EspruinoTools core/serial_websocket_relay.js
var getPorts=function(callback) override.

Espruino.Core.Utils.getJSONURL("/serial/ports", function(ports) {
if (ports===undefined) {
console.log("/serial/ports doesn't exist - disabling WebSocket support");

EspruinoWebIDE server.js

if (url == "/serial/ports") {
  Espruino.Core.Serial.getPorts(function(ports) {
    response.writeHead(200);
    response.end(JSON.stringify(ports,null,2));
  });
  return;
}

Update: this error is there for direct use of IDE @ espruino.com/ide

only_known_devices is causing issues

Hi,

Firstly, thank you for this software. It really allows me to do some cool stuff at my home.

I started noticing some gaps in messages published to my MQTT server which was impacting some automations. I played around the the config file, uninstalled/reinstalled the service, restored my Pi to a previous backup, tried it directly installed and via docker and yet the issue persists. Each time I installed fresh using the stock config, it worked perfectly, but as soon as I edited my config, the problem returned.

I noticed that if I set "only_known_devices" back to the default state of false, all of the problems disappeared.

I am running a raspberry pi 4 on buster arm64. Everything is up to date. I am currently running this via the docker container.

Below is my config. As I said, I only change only_known_devices from true back to false and it works fine. What am I doing wrong? If you need any further info, please let me know. Thanks!

{
  "// If a device's address is here, it'll be given a human-readable name":0,
  "known_devices" : {
    "xx:xx:xx:xx:xx:xx": "keys1",
    "xx:xx:xx:xx:xx:xx": "keys2"
  },

  "// Set this to true to only publish MQTT messages for known devices":0,
  "only_known_devices": true,

  "// How many seconds to wait for a packet before considering BLE connection":0,
  "// broken and exiting. Higher values are useful with slowly advertising sensors.":0,
  "// Setting a value of 0 disables the exit/restart.":0,
  "ble_timeout": 20,

  "// How many seconds to wait for emitting a presence event, after latest time polled":0,
  "// Default is 60 seconds":0,
  "presence_timeout" : 30,
  
  "// Number of simultaneous bluetooth connection the device can handle (PI Zero=4)":0,
  "max_connections" : 4,

  "connection_timeout": 20,

  "// MQTT path for history requests and output. Default is Empty (to disable).":0,
  "//history_path": "/ble/hist/",

  "// We can add our own custom advertising UUIDs here with names to help decode them":0,
  "advertised_services" : {
    "ffff" : {
      "name" : "level"
    }
  },

  "// Make this nonzero to enable the HTTP server on the given port.":0,
  "// See README.md for more info on what it does":0,
  "http_port" : 1888,

  "// Set this to enable the HTTP proxy - it's off by default for safety":0,
  "// since it would be possible to spoof MAC addresses and use your":0,
  "// connection":0,
  "// NOTE: Some Bluetooth adaptors will cause the error: Command Disallowed (0xc)":0,
  "// when trying to connect if http_proxyis enabled.":0,
  "http_proxy" : false,

  "// If there are any addresses here, they are given access to the HTTP proxy":0,
  "http_whitelist" : [
    "e7:e0:57:ad:36:a2"
  ],
  "mqtt_host": "mqtt://localhost",
  "//mqtt_options": {
    "username": "user",
    "password": "pass",
    "clientId": "clientid"
  },
  "// Define the topic prefix under which the MQTT data will be posted. Defaults to /ble which is not adviced. For new installation, please activate the option below.":0,
  "mqtt_prefix": "occupancy"
}

new Dockerfile run on node:10-alpine

What do you think about new Dockerfile run on node:10-alpine

FROM node:10-alpine AS build

RUN set -x \
  && apk add --no-cache --virtual .build-deps \
    build-base \
    linux-headers \
    eudev-dev \
    python \
    git \
  && git clone https://github.com/espruino/EspruinoHub /tmp/espruinohub \
  && cd /tmp/espruinohub \
  && npm i --production --verbose \
  && apk del .build-deps \
  && mkdir /app \
  && mv /tmp/espruinohub/node_modules /tmp/espruinohub/lib /tmp/espruinohub/www /tmp/espruinohub/index.js /tmp/espruinohub/config.json /app/ \
  && rm -rf /tmp/*

FROM node:10-alpine

COPY --from=build /app /app

RUN set -x \
  && apk add --no-cache tzdata

WORKDIR /app

CMD [ "node", "index.js", "-c", "/data/config.json" ]

Cant use HTTPProxy with puck

Hi,

I try to setup my pi as an espruino hub to allow my pucks to do some http requests, but for some reason it wont work :/

From your basic example I get this on the puck:

Connected
Got service
Got characteristic
Set URI
Uncaught Error: Unhandled promise rejection: No Characteristics found

and on my pi I get:

Config loaded
MQTT Connected
<HTTPProxy> Bleno State poweredOn
<HTTPProxy> Bleno.startAdvertising Success
<HTTPProxy> Bleno.setServices Success
Scanning started...
<HTTPProxy> c9:88:f0:97:da:57 connected (whitelisted: undefined)
BLE broken? No advertising packets in 10 seconds - restarting!

Fri Dec 09 2016 20:58:39 GMT+0100 (CET)

47:4d:3d:fd:7b:07 - ? (RSSI -64)
7a:3f:6d:0d:d0:bf - ? (RSSI -72)
ac:bc:32:d2:90:e0 - ? (RSSI -71)
d0:4f:7e:19:13:7d - ? (RSSI -54)
puck1 - Puck.js da57 (RSSI -75)

After some time the process exits. This is my config.json

{
  "// If a device's address is here, it'll be given a human-readable name":0,
  "known_devices" : {
    "c9:88:f0:97:da:57" : "puck1"
  },

  "// Set this to enable the HTTP proxy - it's off by default for safety":0,
  "// since it would be possible to spoof MAC addresses and use your":0,
  "// connection":0,
  "http_proxy" : true,

  "// If there are any addresses here, they are given access to the HTTP proxy":0,
  "http_whitelist" : [
    "c9:88:f0:97:da:57"
  ]
}

Any hints? :)

Thanks!

Connection refused: not authorized

The default configuration doesn't set a client ID. One of the basic settings of the mosquitto broker is requiring a (unique) client ID. The fix is pretty easy; always set a default client ID (e.g. espruinohub). I've stared myself crazy at this issue. I hope to make a pull request to modify the default config for the mqtt_options section tomorrow.

Bluetooth advertising blocking

Hi,

Are there any way I can switch off advertising of my RPi bluetooth ?? I'm using it only to read beacons presence in my house, I don't need http proxy. I only want my RPi with EspruinoHub to read beacons presence. Now my RPi advertising and I can connect to it with BLE apps on my phone and so anyone of my neighbours can.. I think its dangerous to my devices. And when I connect to it, the communication with my beacons are blocked.. Is it possible to turn off advertising ??

README.md Script not working

Hello,

Is it possible for you to check your script on the readme ?

git is not downloaded from apt so maybe you need to add that to the downloaded library.
Then if you copy past all of the script the sudo systemctl enable nodered.service as node red is never downloaded before, so either i'm missing a part or i need to use the commented lines to get node-red, either ways it's not clear at all, especially for an all in one script up to date as mentioned.

Thank you

EspruinoHub publishes presence 0 when it starts

This is a continuation of #67 (I am unable to re-open it for some reason).

This is exactly what I wanted - brilliant and fast solution (thank you), however this is what happens in my case:
Screenshot_20201205_072633
EspruinoHub publishes presence 0 when it starts and immediately pushes correction: 1. Of course this is enough to trigger the action, and the garage gate opens... every time I restart EspruinoHub... :-(

Error while installing EspruinoHub

Hi everybody
I'm new here and I need your help. I'm trying to connect my Ruuvitags with Openhab. So I'm to install node-red which works fine and EspruinoHub.
I did all steps like the description. But at the point where I have to npm install this comes out:

pi@raspberrypi:~ $ cd EspruinoHub
pi@raspberrypi:~/EspruinoHub $ npm install
[email protected] install /home/pi/EspruinoHub/node_modules/usb
node-pre-gyp install --fallback-to-build
node-pre-gyp ERR! Tried to download(404): https://github.com/tessel/node-usb/releases/download/1.3.1/usb_bindings-v1.3.1-node-v57-linux-arm.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v57 ABI, glibc) (falling back to source compile with node-gyp)
make: Entering directory '/home/pi/EspruinoHub/node_modules/usb/build'
CC(target) Release/obj.target/libusb/libusb/libusb/core.o
CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o

Does anyone know what I can do?
Thank you so much

How to uninstall EspruinoHub?

I use EspruinoHub with my Puck.js on a regular basis. I would like to uninstall it in order to install the equivalent docker container. Could you provide some instructions on how to uninstall it properly?

More configuration

Good morning Gordon,

thank you for a brilliant library!. However, I am wondering if one can do more configuration:
a) Add an external Broker (instead of localhost)
b) Influence the topics (at least prefix-wise) and potentially the amount of data sent

And lastly I would like to understand whether the system restarts itself / How and where I can debug it. I implemented your logic for a button press (http://forum.espruino.com/conversations/299127/) and some logic that the Puck.js blinks on a certain MQTT topic. I understand that the two parts are exclusive (either scanning for an advertisement or connecting / sending). However, it works at startup but at some point in time seems to stop working.

Architecture: Using a Raspberry Pi 3B running MQTT on localhost. Running a Python script which translates the most relevant messages (RSSI every minute, commands, button presses) from the localhost MQTT to other, different topics on localhost (in future this will be an external MQTT). So basically bridging the localhost MQTT to a public MQTT for certain commands. The problems seem to occur mostly when I init the above logic on boot, when I start manually it seems slightly more reliable. I am used to Java application level, but a rookie for BLE/Python/Javascript.

send MQTT

hai, i want to know is there a way to make a delay when sending mqtt data, i want to send data like every 1 minutes or else not every 1 second like default espruinoHub does.., thank you.

not starting

Hello Gordon,
I installed on a clean Raspbian Stretch, but after running the script ./start.sh :
./start.sh
setterm: terminal xterm does not support --blank
internal/modules/cjs/loader.js:582
throw err;
^

Error: Cannot find module 'bluetooth-hci-socket'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (/home/pi/EspruinoHub/node_modules/noble/lib/hci-socket/hci.js:6:26)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)

I tried to install the system from scratch again... after npm install:

binding.target.mk:99: recipe for target 'Release/obj.target/binding/src/BluetoothHciSocket.o' failed
make: *** [Release/obj.target/binding/src/BluetoothHciSocket.o] Error 1
make: Leaving directory '/home/pi/EspruinoHub/node_modules/bluetooth-hci-socket/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Linux 4.14.79-v7+
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/pi/EspruinoHub/node_modules/bluetooth-hci-socket
gyp ERR! node -v v10.14.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

[email protected] install /home/pi/EspruinoHub/node_modules/websocket
(node-gyp rebuild 2> builderror.log) || (exit 0)

make: Entering directory '/home/pi/EspruinoHub/node_modules/websocket/build'
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
SOLINK_MODULE(target) Release/obj.target/bufferutil.node
COPY Release/bufferutil.node
CXX(target) Release/obj.target/validation/src/validation.o
SOLINK_MODULE(target) Release/obj.target/validation.node
COPY Release/validation.node
make: Leaving directory '/home/pi/EspruinoHub/node_modules/websocket/build'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/xpc-connection):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/bluetooth-hci-socket):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: node-gyp rebuild
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

added 85 packages from 66 contributors and audited 540 packages in 78.117s
found 1 low severity vulnerability
run npm audit fix to fix them, or npm audit for details

data conversion on notification not working

In my sample application, my bluetooth device (in this case a TurnTouch button) returns a 2-byte buffer. This is working correctly. However in the event handler set up in notify for data events this is constrained into a string:

char.on('data', function (data) { //snipped if (connection.services[serviceUUID][characteristicUUID].notifyCallback) connection.services[serviceUUID][characteristicUUID].notifyCallback(data.toString()); });

For me this always results in the same 4-byte array being returned i.e. 0xefbfbd00, irrespective of the value of data. I believe this is a string conversion issue. The application for me works correctly when the string conversion is removed, i.e. simply

char.on('data', function (data) { //snipped if (connection.services[serviceUUID][characteristicUUID].notifyCallback) connection.services[serviceUUID][characteristicUUID].notifyCallback(data); });

This change may be a breaking change for any app that is expecting a string.

Pull request follows.

[Question] HM-10 and Custom service

I have an arduino+HM-10 that sends data through the "ffe1" service:

sensors/advertise/arduinoBpm -> "{\"rssi\":-71,\"name\":\"pulse\",\"serviceUuids\":[\"ffe1\"],\"manufacturerData\":\"484d64694e21e35c\"}"

sensors/advertise/arduinoBpm/manufacturer/4d48 -> "\"64694e21e35c\"

sensors/advertise/arduinoBpm/rssi -> "-71" 

But I can't achieve to read the actual value !
Here is my config.json :

{
  "// If a device's address is here, it'll be given a human-readable name":0,
  "known_devices" : {
    "64:69:4E:3E:11:5B" : "arduinoGyro",
    "64:69:4E:21:E3:5C" : "arduinoBpm"
  },

  "// Set this to true to only publish MQTT messages for known devices":0,
  "only_known_devices": true,

  "// How many seconds to wait for a packet before considering BLE connection":0,
  "// broken and exiting. Higher values are useful with slowly advertising sensors.":0,
  "// Setting a value of 0 disables the exit/restart.":0,
  "ble_timeout": 36000,

  "// How many seconds to wait for emitting a presence event, after latest time polled":0,
  "// Default is 60 seconds":0,
  "presence_timeout" : 1800,
  
  "// Number of simultaneous bluetooth connection the device can handle (PI Zero=4)":0,
  "max_connections" : 10,

  "connection_timeout": 36000,

  "// MQTT path for history requests and output. Default is Empty (to disable).":0,
  "//history_path": "",

  "// We can add our own custom advertising UUIDs here with names to help decode them":0,
  "advertised_services" : {
    "ffe0" : {
      "name" : "gyroscope"
    },
    "ffe1" : {
      "name" : "cardiac"
    }
  },

  "// Make this nonzero to enable the HTTP server on the given port.":0,
  "// See README.md for more info on what it does":0,
  "http_port" : 1888,

  "// Set this to enable the HTTP proxy - it's off by default for safety":0,
  "// since it would be possible to spoof MAC addresses and use your":0,
  "// connection":0,
  "// NOTE: Some Bluetooth adaptors will cause the error: Command Disallowed (0xc)":0,
  "// when trying to connect if http_proxyis enabled.":0,
  "http_proxy" : false,

  "// If there are any addresses here, they are given access to the HTTP proxy":0,
  "http_whitelist" : [
    "e7:e0:57:ad:36:a2"
  ],
  "mqtt_host": "mqtt://surveillancedevieux-mqtt2.apps.asidiras.dev",
  "//mqtt_options": {
    "username": "",
    "password": "",
    "clientId": ""
  },
  "// Define the topic prefix under which the MQTT data will be posted. Defaults to /ble which is not adviced. For new installation, please activate the option below.":0,
  "mqtt_prefix": "sensors"
}

In the android app : BLE Scanner I can read the value of the service by connecting to the BLE module.
Screenshot_20201228-180241_BLE Scanner

I have this on ip:1888/status.html:

[Config] Config loaded
[HTTPProxy] config.http_proxy=false, not enabling Bleno/Proxy
[MQTT] Connecting...
[HTTP] Server is listening on http://localhost:1888
[HTTP] www directory found at /home/pi/EspruinoHub/www. Web server at http://localhost:1888
[History] history_path value is empty, thus not providing history.
[Discover] Noble StateChange: poweredOn
[MQTT] Connected
[Discover] Starting scan...
[Discover] Scanning started.
[HTTP] Serving /home/pi/EspruinoHub/www/ide.html
[HTTP] Serving /home/pi/EspruinoHub/www/paho-mqtt.js
[HTTP] Mon Dec 28 2020 17:44:11 GMT+0000 (Greenwich Mean Time) Connection accepted.
[HTTP] Websocket MQTT connected
[HTTP] Websocket MQTT closed (WebSocket)
[HTTP] Websocket MQTT closed (MQTT)
[HTTP] Serving /home/pi/EspruinoHub/www/index.html
[HTTP] Serving /home/pi/EspruinoHub/www/rssi.html
[HTTP] Serving /home/pi/EspruinoHub/www/tinydash.css
[HTTP] Serving /home/pi/EspruinoHub/www/tinydash.js
[HTTP] Serving /home/pi/EspruinoHub/www/paho-mqtt.js
[HTTP] Mon Dec 28 2020 17:45:55 GMT+0000 (Greenwich Mean Time) Connection accepted.
[HTTP] Websocket MQTT connected
[HTTP] Websocket MQTT closed (WebSocket)
[HTTP] Websocket MQTT closed (MQTT)
[HTTP] Serving /home/pi/EspruinoHub/www/mqtt.html
[HTTP] Serving /home/pi/EspruinoHub/www/paho-mqtt.js
[HTTP] Mon Dec 28 2020 17:46:11 GMT+0000 (Greenwich Mean Time) Connection accepted.
[HTTP] Websocket MQTT connected

Mon Dec 28 2020 17:54:33 GMT+0000 (Greenwich Mean Time)

arduinoBpm - pulse (RSSI -64)
  b000 => [0,0,0,0]

Can I achieve a similar connection with EspruinoHub ? How can I overcome this ?

Error with npm install

Hello,

I get this error when i run your script from home page.

pi@piUno:~/EspruinoHub $ npm install

> [email protected] install /home/pi/EspruinoHub/node_modules/usb
> prebuild-install --verbose || node-gyp rebuild

prebuild-install info begin Prebuild-install version 5.3.0
prebuild-install info looking for cached prebuild @ /home/pi/.npm/_prebuilds/2643fa-usb-v1.6.0-node-v64-linux-arm.tar.gz
prebuild-install http request GET https://github.com/tessel/node-usb/releases/download/v1.6.0/usb-v1.6.0-node-v64-linux-arm.tar.gz
prebuild-install http 404 https://github.com/tessel/node-usb/releases/download/v1.6.0/usb-v1.6.0-node-v64-linux-arm.tar.gz
prebuild-install WARN install No prebuilt binaries found (target=10.16.0 runtime=node arch=arm libc= platform=linux)
make : on entre dans le répertoire « /home/pi/EspruinoHub/node_modules/usb/build »
  CC(target) Release/obj.target/libusb/libusb/libusb/core.o
  CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o
  CC(target) Release/obj.target/libusb/libusb/libusb/hotplug.o
  CC(target) Release/obj.target/libusb/libusb/libusb/io.o
  CC(target) Release/obj.target/libusb/libusb/libusb/strerror.o
  CC(target) Release/obj.target/libusb/libusb/libusb/sync.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/poll_posix.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/threads_posix.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_usbfs.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_udev.o
  AR(target) Release/obj.target/usb.a
  COPY Release/usb.a
  CXX(target) Release/obj.target/usb_bindings/src/node_usb.o
../src/node_usb.cc: In function ‘void handleHotplug(std::pair<libusb_device*, libusb_hotplug_event>)’:
../src/node_usb.cc:151:58: warning: ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, const char*, int, v8::Local<v8::Value>*)’ is deprecated [-Wdeprecated-declarations]
  Nan::MakeCallback(Nan::New(hotplugThis), "emit", 2, argv);
                                                          ^
In file included from ../src/helpers.h:3:0,
                 from ../src/node_usb.h:21,
                 from ../src/node_usb.cc:1:
../node_modules/nan/nan.h:1001:46: note: declared here
   NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback(
                                              ^~~~~~~~~~~~
  CXX(target) Release/obj.target/usb_bindings/src/device.o
../src/device.cc: In static member function ‘static void Req::default_after(uv_work_t*)’:
../src/device.cc:237:64: warning: ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*)’ is deprecated [-Wdeprecated-declarations]
    Nan::MakeCallback(device, Nan::New(baton->callback), 1, argv);
                                                                ^
In file included from ../src/helpers.h:3:0,
                 from ../src/node_usb.h:21,
                 from ../src/device.cc:1:
../node_modules/nan/nan.h:959:46: note: declared here
   NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback(
                                              ^~~~~~~~~~~~
  CXX(target) Release/obj.target/usb_bindings/src/transfer.o
../src/transfer.cc: In function ‘void handleCompletion(Transfer*)’:
../src/transfer.cc:126:72: warning: ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*)’ is deprecated [-Wdeprecated-declarations]
   Nan::MakeCallback(self->handle(), Nan::New(self->v8callback), 3, argv);
                                                                        ^
In file included from ../src/helpers.h:3:0,
                 from ../src/node_usb.h:21,
                 from ../src/transfer.cc:1:
../node_modules/nan/nan.h:959:46: note: declared here
   NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback(
                                              ^~~~~~~~~~~~
  SOLINK_MODULE(target) Release/obj.target/usb_bindings.node
  COPY Release/usb_bindings.node
make : on quitte le répertoire « /home/pi/EspruinoHub/node_modules/usb/build »

> [email protected] install /home/pi/EspruinoHub/node_modules/bluetooth-hci-socket
> node-gyp rebuild

make : on entre dans le répertoire « /home/pi/EspruinoHub/node_modules/bluetooth-hci-socket/build »
  CXX(target) Release/obj.target/binding/src/BluetoothHciSocket.o
../src/BluetoothHciSocket.cpp: In member function ‘void BluetoothHciSocket::poll()’:
../src/BluetoothHciSocket.cpp:251:95: warning: ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, v8::Local<v8::String>, int, v8::Local<v8::Value>*)’ is deprecated [-Wdeprecated-declarations]
     Nan::MakeCallback(Nan::New<Object>(this->This), Nan::New("emit").ToLocalChecked(), 2, argv);
                                                                                               ^
In file included from ../src/BluetoothHciSocket.cpp:8:0:
../../nan/nan.h:1045:46: note: declared here
   NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback(
                                              ^~~~~~~~~~~~
../src/BluetoothHciSocket.cpp: In member function ‘void BluetoothHciSocket::emitErrnoError()’:
../src/BluetoothHciSocket.cpp:275:72: error: no matching function for call to ‘v8::Function::NewInstance(int, v8::Local<v8::Value> [1])’
   Local<Value> error = errorConstructor->NewInstance(1, constructorArgs);
                                                                        ^
In file included from /home/pi/.node-gyp/10.16.0/include/node/node.h:63:0,
                 from /home/pi/.node-gyp/10.16.0/include/node/node_buffer.h:25,
                 from ../src/BluetoothHciSocket.cpp:7:
/home/pi/.node-gyp/10.16.0/include/node/v8.h:3993:44: note: candidate: v8::MaybeLocal<v8::Object> v8::Function::NewInstance(v8::Local<v8::Context>, int, v8::Local<v8::Value>*) const
   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
                                            ^~~~~~~~~~~
/home/pi/.node-gyp/10.16.0/include/node/v8.h:3993:44: note:   candidate expects 3 arguments, 2 provided
/home/pi/.node-gyp/10.16.0/include/node/v8.h:3996:44: note: candidate: v8::MaybeLocal<v8::Object> v8::Function::NewInstance(v8::Local<v8::Context>) const
   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
                                            ^~~~~~~~~~~
/home/pi/.node-gyp/10.16.0/include/node/v8.h:3996:44: note:   candidate expects 1 argument, 2 provided
../src/BluetoothHciSocket.cpp:282:93: warning: ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, v8::Local<v8::String>, int, v8::Local<v8::Value>*)’ is deprecated [-Wdeprecated-declarations]
   Nan::MakeCallback(Nan::New<Object>(this->This), Nan::New("emit").ToLocalChecked(), 2, argv);
                                                                                             ^
In file included from ../src/BluetoothHciSocket.cpp:8:0:
../../nan/nan.h:1045:46: note: declared here
   NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback(
                                              ^~~~~~~~~~~~
../src/BluetoothHciSocket.cpp: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE BluetoothHciSocket::BindRaw(Nan::NAN_METHOD_ARGS_TYPE)’:
../src/BluetoothHciSocket.cpp:395:34: warning: ‘int64_t v8::Value::IntegerValue() const’ is deprecated: Use maybe version [-Wdeprecated-declarations]
       devId = arg0->IntegerValue();
                                  ^
In file included from /home/pi/.node-gyp/10.16.0/include/node/v8.h:26:0,
                 from /home/pi/.node-gyp/10.16.0/include/node/node.h:63,
                 from /home/pi/.node-gyp/10.16.0/include/node/node_buffer.h:25,
                 from ../src/BluetoothHciSocket.cpp:7:
/home/pi/.node-gyp/10.16.0/include/node/v8.h:2476:46: note: declared here
   V8_DEPRECATED("Use maybe version", int64_t IntegerValue() const);
                                              ^
/home/pi/.node-gyp/10.16.0/include/node/v8config.h:324:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../src/BluetoothHciSocket.cpp: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE BluetoothHciSocket::BindUser(Nan::NAN_METHOD_ARGS_TYPE)’:
../src/BluetoothHciSocket.cpp:417:34: warning: ‘int64_t v8::Value::IntegerValue() const’ is deprecated: Use maybe version [-Wdeprecated-declarations]
       devId = arg0->IntegerValue();
                                  ^
In file included from /home/pi/.node-gyp/10.16.0/include/node/v8.h:26:0,
                 from /home/pi/.node-gyp/10.16.0/include/node/node.h:63,
                 from /home/pi/.node-gyp/10.16.0/include/node/node_buffer.h:25,
                 from ../src/BluetoothHciSocket.cpp:7:
/home/pi/.node-gyp/10.16.0/include/node/v8.h:2476:46: note: declared here
   V8_DEPRECATED("Use maybe version", int64_t IntegerValue() const);
                                              ^
/home/pi/.node-gyp/10.16.0/include/node/v8config.h:324:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
binding.target.mk:99 : la recette pour la cible « Release/obj.target/binding/src/BluetoothHciSocket.o » a échouée
make: *** [Release/obj.target/binding/src/BluetoothHciSocket.o] Erreur 1
make : on quitte le répertoire « /home/pi/EspruinoHub/node_modules/bluetooth-hci-socket/build »
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.19.42-v7+
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/pi/EspruinoHub/node_modules/bluetooth-hci-socket
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

> [email protected] install /home/pi/EspruinoHub/node_modules/websocket
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make : on entre dans le répertoire « /home/pi/EspruinoHub/node_modules/websocket/build »
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
  SOLINK_MODULE(target) Release/obj.target/bufferutil.node
  COPY Release/bufferutil.node
  CXX(target) Release/obj.target/validation/src/validation.o
  SOLINK_MODULE(target) Release/obj.target/validation.node
  COPY Release/validation.node
make : on quitte le répertoire « /home/pi/EspruinoHub/node_modules/websocket/build »
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/xpc-connection):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/bluetooth-hci-socket):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

added 343 packages from 241 contributors and audited 7083 packages in 110.278s
found 1 low severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details````

unclear how to get HomeAssistant to discover sensor

I'm trying to set up a Puck.js v2 to use as a doorbell. I'm looking at the notes here and in home assistant.

I've got the raspberry pi runnig the espruino/EspruinoHub to connect to HomeAsisstant:
Apr 22 19:13:04 enviro EspruinoHub[16341]: [MQTT] Connected
and I can see some MQTT messages in HomeAssistant, listening to doorbell/#
Message 41 received on doorbell/presence/xx:xx:xx:xx:73:d9 at 7:22 PM:
1

(that's not my... device by the way.. I don't know what that is)

But I can't get the automatic discovery to work.

My puck is set to do this:

//doorbell advertise bluetooth

NRF.setTxPower(4); // Full Power advertising

//watch doorbell button
var pressCount = 0;
setWatch(function() {
  pressCount++;
  NRF.setAdvertising({
    0xFFFF : pressCount
  });
  digitalPulse(LED3, 1, 1000);
}, BTN, { edge:"falling", repeat:true, debounce:50 });


//advertise 
//temperature and battery level
setInterval(function() {
  NRF.setAdvertising(
    {
    0x1809 : Math.round(E.getTemperature())
    },
    {
    0x180F : E.getBatteryPercentage() 
    }
                    );
}, 5*60*1000);// 5 mins


//setInterval(function() {
//  NRF.setAdvertising({
//    0x180F : E.getBatteryPercentage()
//  },{name: "puckName", interval: 1000});
//}, 30*1000); // 30 seconds

and my config.js is set to to do this:

{
  "// If a device's address is here, it'll be given a human-readable name":0,
  "known_devices" : {
    "xx:xx:xx:xx:1f:8c" : "doorbell"   //(MY PUCK, I THINK)
  },

  "// Set this to true to only publish MQTT messages for known devices":0,
  "only_known_devices": false,

  "// How many seconds to wait for a packet before considering BLE connection":0,
  "// broken and exiting. Higher values are useful with slowly advertising sensors.":0,
  "// Setting a value of 0 disables the exit/restart.":0,
  "ble_timeout": 20,

  "// How many seconds to wait for emitting a presence event, after latest time polled":0,
  "// Default is 60 seconds":0,
  "presence_timeout" : 30,

  "// Number of simultaneous bluetooth connection the device can handle (PI Zero=4)":0,
  "max_connections" : 4,

  "connection_timeout": 20,

  "// MQTT path for history requests and output. Default is Empty (to disable).":0,
  "//history_path": "/ble/hist/",

  "// We can add our own custom advertising UUIDs here with names to help decode them":0,
  "advertised_services" : {
    "ffff" : {
      "name" : "level"
    }
  },

  "// Make this nonzero to enable the HTTP server on the given port.":0,
  "// See README.md for more info on what it does":0,
  "http_port" : 1888,

  "// Set this to enable the HTTP proxy - it's off by default for safety":0,
  "// since it would be possible to spoof MAC addresses and use your":0,
  "// connection":0,
  "// NOTE: Some Bluetooth adaptors will cause the error: Command Disallowed (0xc)":0,
  "// when trying to connect if http_proxyis enabled.":0,
  "http_proxy" : true,

  "// If there are any addresses here, they are given access to the HTTP proxy":0,
  "http_whitelist" : [
    "xx:xx:xx:xx:1f:8c" //(MY PUCK, I THINK. )
  ],
  "mqtt_host": "mqtt://x.x.x.x", //(REMOTE HOME ASSISTANT ON LAN)
  "mqtt_options": {
    "username": "espruinodoorbell",
    "password": "xxxxxxxxx",
    "clientId": "doorbell"
  },
  "// Define the topic prefix under which the MQTT data will be posted. Defaults to /ble which is not adviced. For new installation, please activate the option below.":0,
  "mqtt_prefix": "/doorbella",

  "// These are the types of MQTT topics that are created":0,
  
  "// Send /ble/advertise/ad:dr:es:ss JSON with raw advertising data, as well as /ble/advertise/ad:dr:es:ss/rssi":0,
  "// This is used by the localhost:1888/ide service to detect devices":0,
  "mqtt_advertise": true,
  "// Send /ble/advertise/ad:dr:es:ss/manufacturer/uuid raw manufacturer data as well as decoded /ble/advertise/ad:dr:es:ss/json_key for json-formatted 0x0590 advertising data":0,
  "mqtt_advertise_manufacturer_data": false,
  "// Send /ble/advertise/ad:dr:es:ss/uuid raw service data":0,
  "mqtt_advertise_service_data": false,
  "// Send /ble/json/ad:dr:es:ss/uuid for decoded service data - REQUIRED FOR HOMEASSISTANT":0,
  "mqtt_format_json": true,
  "// Send /ble/service_name/ad:dr:es:ss for decoded service data":0,
  "mqtt_format_decoded_key_topic": true,

  "// Whether to enable Home Assistant integration":0,
  "homeassistant": true
}

... I'm slightly confused as to how to proceed. Any help gratefully received! I've putting tried all manner of keywords into the 'mqtt_prefix' line, homeassistant/ sensor/ etc. What am I doing wrong?

ExpruinoHub shuts down right after it starts

I installed ExpruinoHub in a Raspberry Pi 3. Used node v8.15.0.

It installs OK but when I run ./start.sh I see the following:

MQTT> Connecting...
<HTTP> Server is listening on http://localhost:1888
<HTTP> www directory found at /home/pi/puckjs/EspruinoHub/www. Web server at http://localhost:1888
<History> log directory found at /home/pi/puckjs/EspruinoHub/log. Enabling logging.
<Discover> Noble StateChange: poweredOff
<MQTT> Connected
<Discover> BLE broken? No Noble State Change to 'poweredOn' in 20 seconds - restarting!

Fri Feb 22 2019 20:49:36 GMT+0000 (UTC)

Do I need to power on Bluetooth LE first in the Pi?

Install Documents - minor updates or questions

Based on a recent install, just a few minor tweaks in bold below...

sorry, formatting got messed up when pasting here.

sudo apt-get update
sudo apt-get upgrade -y **# this seems like a good step to do**
sudo apt-get install -y build-essential python-rpi.gpio nodejs nodered **_git_** **# ← -y for unattended and need git**
# OPTIONAL: Install a modern version of nodejs and nodered
# Not recommended - The Pi's supplied Node.js version is more than good enough
# bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)
# Get dependencies
sudo apt-get install -y mosquitto mosquitto-clients bluetooth bluez libbluetooth-dev libudev-dev **# ← -y for unattended**
# Auto start Node-RED
sudo systemctl enable nodered.service
# Start nodered manually this one time (this creates ~/.node-red)
sudo systemctl start nodered.service **# wait for the ~/.node-red directory to get created ...**
# Install the Node-RED UI
**#cd ~/.node-red && npm install node-red-contrib-ui   ← which dashboard UI is better**
**cd ~/.node-red && npm install node-red-dashboard**
# Now get EspruinoHub
cd ~/
git clone https://github.com/espruino/EspruinoHub
# Install EspruinoHub's required Node libraries
cd EspruinoHub
npm install
# Optional - enable gathering of historical data by creating a 'log' directory
**# mkdir log ← not needed as a separate step anymore**
# Give Node.js access to Bluetooth
sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)

Crash when viewing rssi.html or mqtt.html

When I view either of those pages EspruinoHub crashes with this error.

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND hassio.local:1883
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (internal/streams/destroy.js:100:8)
    at emitErrorCloseNT (internal/streams/destroy.js:68:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'hassio.local:1883'
}

Presense is flapping

I started to observe this issue since the last update of bluez to version 5.50.
This is my config:

{
  "known_devices" : {
    "12:AA:AA:AA:AA:99" : "test",
  },
  "only_known_devices": true,
  "ble_timeout" : 0,
  "presence_timeout" : 10,
  "max_connections" : 4,
  "connection_timeout": 20,
  "advertised_services" : {
    "ffff" : {
      "name" : "level"
    }
  },
  "http_port" : 1888,
  "http_proxy" : false,
  "http_whitelist" : [
  ],
  "mqtt_host": "mqtt://mqtt.my.host,
  "mqtt_options": {
    "username": "mqtt_user",
    "password": "mqtt_passwd",
    "clientId": "clientid"
  },
  "mqtt_prefix": "bluetooth-test"
}

Flapping

Screenshot_20201204_083528

The test beacon sits all the time on the same spot (check the rssi?). As you can see the presence of my test device is flapping like crazy. Which renders the whole idea useless.
This does not happen right after I run the EspruinoHub. It begins acting that way after some time (5, 10, 30 minutes) it is very nondeterministic... But when it starts, it keeps going like that.

MQTT Connected (over and over)

I have also noticed that EspruinoHub started to generate huge number of [MQTT] Connected messages. The start of the service service looks like that:

Dec 04 08:31:58 beacon ble-beacon[1248]: Starting without Bleno (GATT Server)
Dec 04 08:31:59 beacon ble-beacon[1248]: [Config] Config config.json loaded
Dec 04 08:31:59 beacon ble-beacon[1248]: [HTTPProxy] config.http_proxy=false, not enabling Bleno/Proxy
Dec 04 08:32:00 beacon ble-beacon[1248]: [MQTT] Connecting...
Dec 04 08:32:00 beacon ble-beacon[1248]: [HTTP] Server is listening on http://localhost:1888
Dec 04 08:32:00 beacon ble-beacon[1248]: [HTTP] www directory found at /opt/ble-beacon/www. Web server at http://localhost:1888
Dec 04 08:32:00 beacon ble-beacon[1248]: [History] history_path value is empty, thus not providing history.
Dec 04 08:32:00 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:00 beacon ble-beacon[1248]: [Discover] Noble StateChange: poweredOn
Dec 04 08:32:01 beacon ble-beacon[1248]: [Discover] Starting scan...
Dec 04 08:32:01 beacon ble-beacon[1248]: [Discover] Scanning started.
Dec 04 08:32:02 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:04 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:06 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:08 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:10 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:12 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:14 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:16 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:18 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:20 beacon ble-beacon[1248]: [MQTT] Connected
Dec 04 08:32:22 beacon ble-beacon[1248]: [MQTT] Connected
[...]
Dec 04 08:32:24 beacon ble-beacon[1248]: [MQTT] Connected
[...]

and it keeps polluting the log.

I am not sure what is causing this problem, as your solution was rock-solid before...

Device disconnects even when notifications are being received.

24:e5:aa:47:ad:cb: Getting Service...
24:e5:aa:47:ad:cb: found service: 477ea600a26011e4ae370002a5d50002
24:e5:aa:47:ad:cb: found characteristic: 477ea600a26011e4ae370002a5d54090
24:e5:aa:47:ad:cb: startNotifications complete
24:e5:aa:47:ad:cb: Disconnecting due to lack of use (after 20 secs)
24:e5:aa:47:ad:cb: Disconnecting.
24:e5:aa:47:ad:cb: Disconnected

Commands do not work anymore

Hello Gordon,

I have a function blink(). When I call this (either from WEB-IDE or Nordic from my mobile) it blinks the LED. So far so good. Now I try to connect to this via MQTT: mosquitto_pub -t "/ble/write/e5:c8:14:d4:de:27/nus/nus_tx" -m "blink();\n"

But nothing happens, though it did work before. Do you have any ideas?

Hangs when connecting to Puck.js or MDBT42Q

Hey, I have EspruinoHub installed on Pi3 with fresh base of 2020-02-13-raspbian-buster-lite. The server runs, start.sh even outputs the RSSI values for my local devices, but it's unable to connect from the IDE.

With the Puck on EspruinoHub (using firmware 2v04 and tested to make sure it still works with Web IDE) the "Connecting..." dialog never goes away. This is what the dev console outputs:

/serial/ports doesn't exist - disabling WebSocket support
>>> Connecting...
Set Slow Write = true
Connected 
Object { ok: true }
Got ""
No Prompt found, got undefined - issuing Ctrl-C to try and break out
Still no prompt - issuing another Ctrl-C

The MDBT42Q does the same thing but the console says:

/serial/ports doesn't exist - disabling WebSocket support
>>> Connecting...
Set Slow Write = true
Connected 
Object { ok: true }
Found a prompt... great!
>>> Sending...
---> "\u0010print(\"<\",\"<<\",JSON.stringify(process.env),\">>\",\">\")\n"

I tried a few fresh setups using both sets of instructions for installation (with node-red and without) and this same issue happens both times.

As far as I can remember this same set of steps worked in the past so maybe it's the current raspbian or a library version or something?

Xiaomi Mi smartband 6

Just bought a Xiaomi MI band 6 and want to read the heartrate.
It will connect to the hub but I see no advertising data at all.
Is there anything I have to change in xiaomi.js to see the values of this device?
Maybe the xiaomiProductName has to been added?

scanStopCallback is not defined

On a fresh install i get follwing error:

/home/pi/EspruinoHub/lib/discovery.js:202
    if (scanStopCallback) {
    ^

ReferenceError: scanStopCallback is not defined
    at Noble.<anonymous> (/home/pi/EspruinoHub/lib/discovery.js:202:5)
    at Noble.emit (events.js:198:13)
    at Noble.onScanStop (/home/pi/EspruinoHub/node_modules/@abandonware/noble/lib/noble.js:164:8)
    at NobleBindings.emit (events.js:198:13)
    at NobleBindings.onScanStop (/home/pi/EspruinoHub/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:133:8)
    at Gap.emit (events.js:198:13)
    at Gap.onLeScanEnableSetCmd (/home/pi/EspruinoHub/node_modules/@abandonware/noble/lib/hci-socket/gap.js:86:12)
    at Hci.emit (events.js:198:13)
    at Hci.onSocketData (/home/pi/EspruinoHub/node_modules/@abandonware/noble/lib/hci-socket/hci.js:534:12)
    at BluetoothHciSocket.emit (events.js:198:13)

Can you help me?

Installation Docs - updates

Two suggested changes

  1. The apt installation of the rpi.gpio package has changed to the one noted below
  2. The older node-red dashboard has been deprecated in favor of the one noted below.

sudo apt-get install -y build-essential nodejs nodered git-core rpi.gpio #python-rpi.gpio
cd ~/.node-red && npm install node-red-dashboard #node-red-contrib-ui

Some refactoring needed "fe95" for many Xiaomi devices

Hi,

the current implementation is very specific for the "Xiaomi Mija LYWSDCGQ/01ZM".
Other Xiaomi devices (yee-rc and Amazfit watches) advertise the same service "fe95".
I'll try to do some refactoring to support more Xiaomi device types.

Services exposed by my Xiaomi Amazfit Stratos watch:

[{"uuid":"1800","characteristics":[{"uuid":"2a00"},{"uuid":"2a01"}]},{"uuid":"1801","characteristics":[{"uuid":"2a05"}]},{"uuid":"0000fed00000351221180009af100700","characteristics":[{"uuid":"000000010000351221180009af100700"},{"uuid":"000000080000351221180009af100700"},{"uuid":"000000090000351221180009af100700"},{"uuid":"000000100000351221180009af100700"},{"uuid":"000000110000351221180009af100700"},{"uuid":"000000120000351221180009af100700"},{"uuid":"000000200000351221180009af100700"},{"uuid":"000000130000351221180009af100700"},{"uuid":"000000510000351221180009af100700"}]},{"uuid":"0000fed10000351221180009af100700","characteristics":[{"uuid":"0000fed20000351221180009af100700"}]},{"uuid":"fee1","characteristics":[{"uuid":"fedd"},{"uuid":"fede"}]}]

Set presence to 0 for non-present `known devices` when the app starts.

Could you please consider setting the presence to 0 when we have defined known devices but the device is not present when the EspruinoHub starts?
Occasionally I need to clean the MQTT broker (for test/maintenance reason) and when the EspruinoHub starts AND the known device is not available, its presence is not reported. This messes a bit with my automation.

nordic nrf52840 running Circuitpython

Hi there.

I found this, searching for an BLE nordic UART Service to MQTT relay.
I'am using Circuitpython and i am wondering if I can use your software to get a connection to my NRF52840 running Circuitpython.

Do you think this is possible?

Auto Start Service doesn't scan.

When I follow the instruction in the README for Auto Start, the service starts up as normal, but never starts scanning. See the journalctl output:

-- Logs begin at Thu 2016-11-03 17:16:42 UTC, end at Thu 2018-10-04 15:07:10 UTC. --
Oct 04 15:06:53 raspberrypi systemd[1]: Started EspruinoHub BLE -> MQTT bridge.
Oct 04 15:06:53 raspberrypi EspruinoHub[328]: setterm: $TERM is not defined.
Oct 04 15:06:53 raspberrypi sudo[354]:       pi : TTY=unknown ; PWD=/home/pi/EspruinoHub ; USER=root ; COMMAND=/sbin/setcap cap_net_raw+eip /usr/bin/node
Oct 04 15:06:53 raspberrypi sudo[354]: pam_unix(sudo:session): session opened for user root by (uid=0)
Oct 04 15:06:53 raspberrypi sudo[354]: pam_unix(sudo:session): session closed for user root
Oct 04 15:06:54 raspberrypi EspruinoHub[328]: <Config> Config loaded
Oct 04 15:06:55 raspberrypi EspruinoHub[328]: <MQTT> Connecting...
Oct 04 15:06:56 raspberrypi EspruinoHub[328]: <HTTP> Server is listening on http://localhost:1888
Oct 04 15:06:56 raspberrypi EspruinoHub[328]: <HTTP> www directory found at /home/pi/EspruinoHub/www. Web server at http://localhost:1888
Oct 04 15:06:56 raspberrypi EspruinoHub[328]: <History> log directory found at /home/pi/EspruinoHub/log. Enabling logging.
Oct 04 15:06:56 raspberrypi EspruinoHub[328]: <MQTT> Connected

However, if I manually restart the service using the commands below, everything works fine. Any ideas why it works manually but not at start?

sudo systemctl stop EspruinoHub.service
sudo systemctl start EspruinoHub.service

journalctl output:

-- Logs begin at Thu 2016-11-03 17:16:42 UTC, end at Thu 2018-10-04 15:14:42 UTC. --
Oct 04 15:06:53 raspberrypi systemd[1]: Started EspruinoHub BLE -> MQTT bridge.
Oct 04 15:06:53 raspberrypi EspruinoHub[328]: setterm: $TERM is not defined.
Oct 04 15:06:53 raspberrypi sudo[354]:       pi : TTY=unknown ; PWD=/home/pi/EspruinoHub ; USER=root ; COMMAND=/sbin/setcap cap_net_raw+eip /usr/bin/node
Oct 04 15:06:53 raspberrypi sudo[354]: pam_unix(sudo:session): session opened for user root by (uid=0)
Oct 04 15:06:53 raspberrypi sudo[354]: pam_unix(sudo:session): session closed for user root
Oct 04 15:06:54 raspberrypi EspruinoHub[328]: <Config> Config loaded
Oct 04 15:06:55 raspberrypi EspruinoHub[328]: <MQTT> Connecting...
Oct 04 15:06:56 raspberrypi EspruinoHub[328]: <HTTP> Server is listening on http://localhost:1888
Oct 04 15:06:56 raspberrypi EspruinoHub[328]: <HTTP> www directory found at /home/pi/EspruinoHub/www. Web server at http://localhost:1888
Oct 04 15:06:56 raspberrypi EspruinoHub[328]: <History> log directory found at /home/pi/EspruinoHub/log. Enabling logging.
Oct 04 15:06:56 raspberrypi EspruinoHub[328]: <MQTT> Connected
Oct 04 15:08:41 raspberrypi EspruinoHub[328]: <HTTP> Thu Oct 04 2018 15:08:41 GMT+0000 (UTC) Connection accepted.
Oct 04 15:08:41 raspberrypi EspruinoHub[328]: <HTTP> Websocket MQTT connected
Oct 04 15:08:42 raspberrypi EspruinoHub[328]: <HTTP> Websocket MQTT closed (WebSocket)
Oct 04 15:08:42 raspberrypi EspruinoHub[328]: <HTTP> Websocket MQTT closed (MQTT)
Oct 04 15:14:24 raspberrypi systemd[1]: Stopping EspruinoHub BLE -> MQTT bridge...
Oct 04 15:14:24 raspberrypi systemd[1]: EspruinoHub.service: Main process exited, code=exited, status=1/FAILURE
Oct 04 15:14:24 raspberrypi systemd[1]: Stopped EspruinoHub BLE -> MQTT bridge.
Oct 04 15:14:24 raspberrypi systemd[1]: EspruinoHub.service: Unit entered failed state.
Oct 04 15:14:24 raspberrypi systemd[1]: EspruinoHub.service: Failed with result 'exit-code'.
Oct 04 15:14:36 raspberrypi systemd[1]: Started EspruinoHub BLE -> MQTT bridge.
Oct 04 15:14:36 raspberrypi EspruinoHub[659]: setterm: $TERM is not defined.
Oct 04 15:14:36 raspberrypi sudo[669]:       pi : TTY=unknown ; PWD=/home/pi/EspruinoHub ; USER=root ; COMMAND=/sbin/setcap cap_net_raw+eip /usr/bin/node
Oct 04 15:14:36 raspberrypi sudo[669]: pam_unix(sudo:session): session opened for user root by (uid=0)
Oct 04 15:14:36 raspberrypi sudo[669]: pam_unix(sudo:session): session closed for user root
Oct 04 15:14:36 raspberrypi EspruinoHub[659]: <Config> Config loaded
Oct 04 15:14:36 raspberrypi EspruinoHub[659]: <MQTT> Connecting...
Oct 04 15:14:37 raspberrypi EspruinoHub[659]: <HTTP> Server is listening on http://localhost:1888
Oct 04 15:14:37 raspberrypi EspruinoHub[659]: <HTTP> www directory found at /home/pi/EspruinoHub/www. Web server at http://localhost:1888
Oct 04 15:14:37 raspberrypi EspruinoHub[659]: <History> log directory found at /home/pi/EspruinoHub/log. Enabling logging.
Oct 04 15:14:37 raspberrypi EspruinoHub[659]: <MQTT> Connected
Oct 04 15:14:37 raspberrypi EspruinoHub[659]: <HTTPProxy> Bleno State poweredOn
Oct 04 15:14:37 raspberrypi EspruinoHub[659]: <HTTPProxy> Bleno.startAdvertising Success
Oct 04 15:14:37 raspberrypi EspruinoHub[659]: <HTTPProxy> Bleno.setServices Success
Oct 04 15:14:38 raspberrypi EspruinoHub[659]: <Discover> Starting scan...
Oct 04 15:14:38 raspberrypi EspruinoHub[659]: <Discover> Scanning started.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.