README.md 3.77 KB
Newer Older
Spencer Williams's avatar
Spencer Williams committed
1
Cascade Hello World (Node.js) Snap
Mikhail Vataleu's avatar
Mikhail Vataleu committed
2
====
Spencer Williams's avatar
Spencer Williams committed
3
4
5

See the tutorial: https://deviceops.rigado.com/projects/cascade/en/latest/prototyping/sensor-cloud.html

6
7
8
9
10
11
Example of snapped Node.js application for communications with [Nordic Thingy:52](https://www.nordicsemi.com/eng/Products/Nordic-Thingy-52).
The application is daemon which discovers Nordic Thingy:52 and resends data to MQTT Broker according to the [config file](./config.json).

## Configuration

Configuration file: [./config.json](./config.json)
Spencer Williams's avatar
Spencer Williams committed
12

13
 * `ble` - section store configuration related with Bluetooth
14
 * `ble.deviceMAC` - string can be `"*"` and connects to any available Nordic Thingy:52 or `"CF:AA:13:A1:5C:A5"` and connects to particular device
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 * `mqtt` - configuration of connection to MQTT Broker
 * `mqtt.topic` - can contain placeholder `{hostname}` which will be replaced by gateway hostname on application startup

## Prerequisites

Make sure you have [Node.js](http://nodejs.org/) (>=6.11.4) installed.
This application is using [Nordic-Thingy52-Nodejs](https://github.com/NordicPlayground/Nordic-Thingy52-Nodejs) to handle the Bluetooth connection.

#### Linux

 * Kernel version 3.6 or above
 * ```libbluetooth-dev```

#### Ubuntu/Debian/Raspbian (locally)

Mikhail Vataleu's avatar
Mikhail Vataleu committed
30
31
```bash
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
32
33
34
```

## Running locally
Mikhail Vataleu's avatar
Mikhail Vataleu committed
35
36

```bash
Spencer Williams's avatar
Spencer Williams committed
37
38
git clone git@git.rigado.com:cascade/rigado-node-hello-world.git
cd rigado-node-hello-world
Mikhail Vataleu's avatar
Mikhail Vataleu committed
39
40
npm install
npm run start
41
42
43
44
```

## Building snap

Spencer Williams's avatar
Spencer Williams committed
45
#### RPI3 runnning Ubuntu Core 16.04 (armhf)
46
47

 * Setup [development tools](https://developer.ubuntu.com/core/get-started/developer-setup) (snap classic)
Mikhail Vataleu's avatar
Mikhail Vataleu committed
48
49
50
51
52
53

```bash
snap install classic --edge --devmode
sudo classic
sudo apt update
sudo apt install snapcraft build-essential git
Mikhail Vataleu's avatar
Mikhail Vataleu committed
54
```
Mikhail Vataleu's avatar
Mikhail Vataleu committed
55

56
 * Install [BlueZ](http://www.bluez.org/)
Mikhail Vataleu's avatar
Mikhail Vataleu committed
57
58
59
60
61
62

```bash
snap install bluez
snap connect bluez:bluetooth-control
snap connect bluez:network-control
snap connect bluez:home
Mikhail Vataleu's avatar
Mikhail Vataleu committed
63
```
Mikhail Vataleu's avatar
Mikhail Vataleu committed
64

65
 * Go to the project directory run: ```snapcraft```
66
 * Result file is `./rigado-node-hello-world_0.0.1_armhf.snap`
67
68
69

## Installing snap

Spencer Williams's avatar
Spencer Williams committed
70
71
72
#### Rigado Cascade 500 running Ubuntu Core 16.04 (armhf)

 * Setup brand packages:
Mikhail Vataleu's avatar
Mikhail Vataleu committed
73
74
75
76
77
78

```bash
snap stop --disable rigado-devkit
snap install rigado-edge-connect --edge --devmode
snap connect rigado-edge-connect:bluetooth-control
snap connect rigado-edge-connect:physical-memory-control
79
```
Mikhail Vataleu's avatar
Mikhail Vataleu committed
80

81
 * Install [BlueZ](http://www.bluez.org/)
Mikhail Vataleu's avatar
Mikhail Vataleu committed
82
83
84
85
86
87

```bash
snap install bluez
snap connect bluez:bluetooth-control
snap connect bluez:network-control
snap connect bluez:home
Mikhail Vataleu's avatar
Mikhail Vataleu committed
88
```
Mikhail Vataleu's avatar
Mikhail Vataleu committed
89

90
91
 * Copy `./rigado-node-hello-world_0.0.1_armhf.snap` in to the gateway home directory.
 * Run install command: `sudo snap install ~/rigado-node-hello-world_0.0.1_armhf.snap --dangerous`
92
 * Connect plugs:
Mikhail Vataleu's avatar
Mikhail Vataleu committed
93
94

```bash
95
96
97
98
99
snap stop --disable rigado-node-hello-world
snap connect rigado-node-hello-world:network :network
snap connect rigado-node-hello-world:bluetooth-control :bluetooth-control
snap connect rigado-node-hello-world:network-control :network-control
snap start --enable rigado-node-hello-world
100
```
101
102
103

## Troubleshoot

104
#### HCI devices list is empty
105

Spencer Williams's avatar
Spencer Williams committed
106
 * `sudo bluez.hcitool dev` show empty list of devices.
107
 * Enable HCI devices:
Mikhail Vataleu's avatar
Mikhail Vataleu committed
108
109
110
111

```bash
sudo bluez.bluetoothctl
power on
112
113
```

114
#### CERT_NOT_YET_VALID when snap is crafting
Spencer Williams's avatar
Spencer Williams committed
115

116
 * Switch to `classic` mode.
117
 * Execute following commands:
Mikhail Vataleu's avatar
Mikhail Vataleu committed
118
119
120
121
122
123

```bash
sudo service ntp stop
sudo ntpdate -s time.nist.gov
sudo service ntp start
sudo update-ca-certificates
Mikhail Vataleu's avatar
Mikhail Vataleu committed
124
```
Mikhail Vataleu's avatar
Mikhail Vataleu committed
125
126
127
128

#### `Command Disallowed (0xc)` while app is running on VESTA Gateway

By default, the application uses `hci0` interface which can be locked by other snap.
129
130
131
132
133
134
135
136
137
138
To avoid this issue disable or remove other snaps which use `hci0` interface.

#### `NobleDevice.connectAndSetUp` callback sometimes not invoke

 * Reset Thingy power supply.
 * Restart daemon, run:

```bash
snap stop rigado-node-hello-world
snap start rigado-node-hello-world
Spencer Williams's avatar
Spencer Williams committed
139
```