Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit 693e5f1

Browse files
committed
Linux/RPi edgent update
1 parent 372db6d commit 693e5f1

File tree

3 files changed

+29
-42
lines changed

3 files changed

+29
-42
lines changed

examples/Edgent_Linux_RPi/BlynkEdgent.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
"""
2-
[x] WiFi AP
3-
[x] HTTP server
4-
[x] HTTP handlers
5-
[x] Get own MAC (BSSID)
6-
[ ] OTA update (from app)
7-
[x] WiFi Scanner
8-
[x] WiFi STA
9-
[x] Set hostname
10-
[ ] Static IP support
11-
[ ] Detect auth failure (wrong password?)
12-
[ ] Save/Load config
13-
[ ] Reset button -> Config mode
14-
[ ] Indicator
15-
[ ] Enter config mode on invalid auth
16-
[ ] Report last error
17-
18-
PolKit configuration (if necessary)
19-
https://askubuntu.com/questions/668411/failed-to-add-activate-connection-32-insufficient-privileges/752168#752168
20-
21-
Manual wifi config:
22-
https://unix.stackexchange.com/questions/145366/how-to-connect-to-an-802-1x-wireless-network-via-nmcli
23-
"""
241

252
from http.server import BaseHTTPRequestHandler, HTTPServer
263
from urllib.parse import urlparse, parse_qsl
@@ -30,9 +7,6 @@
307
import json
318
import binascii
329

33-
import os
34-
os.system('sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 11080')
35-
3610
def log(*args, **kwargs):
3711
print(*args, file=sys.stderr, **kwargs)
3812

@@ -121,29 +95,25 @@ def do_GET(self):
12195
elif o.path == "/wifi_scan.json":
12296
self._reply_json(self.server.wifi_networks)
12397
elif o.path == "/config":
124-
q["auth"] = q.pop("blynk")
98+
q["auth"] = q.pop("blynk")
12599
q["server"] = q.pop("host")
100+
q["port"] = int(q.pop("port"))
101+
q["port_ssl"] = int(q.pop("port_ssl"))
126102
if "save" in q:
127103
self._reply_json({"status":"ok","msg":"Configuration saved"})
128104
else:
129105
self._reply_json({"status":"ok","msg":"Trying to connect..."})
130106
self.server.blynk_config = q
131-
elif o.path == "/reset":
132-
self._reply_json({"status":"ok","msg":"Configuration reset"})
133-
self.server.blynk_config = { "cmd": "reset" }
134-
elif o.path == "/reboot":
135-
self._reply_json({"status":"ok"})
136-
self.server.blynk_config = { "cmd": "reboot" }
137107
else:
138108
self.send_error(404)
139109

140-
def provision(board, tmpl_id, fw_ver):
110+
def provision(board, tmpl_id, fw_ver, prefix = "Blynk"):
141111
wifi = WiFi()
142112

143113
wifi_networks = wifi.scan()
144114

145115
suffix = format(binascii.crc32(wifi.mac_address().encode() * 4) & 0xFFFFF, 'X')
146-
my_ssid = "Blynk " + board + "-" + suffix
116+
my_ssid = prefix + " " + board + "-" + suffix
147117

148118
config = None
149119
try:
@@ -161,6 +131,8 @@ def provision(board, tmpl_id, fw_ver):
161131
}
162132
httpd.wifi_networks = wifi_networks
163133
httpd.blynk_config = None
134+
135+
log("Waiting for Blynk App connection...")
164136
while httpd.blynk_config is None:
165137
httpd.handle_request()
166138
config = httpd.blynk_config

examples/Edgent_Linux_RPi/README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

2+
**Warning:** Do not use SSH/remote desktop for these commands, as your network connection can become unavailable.
3+
Connect screen and keyboard to your RPi, or use a serial adapter to access console.
4+
5+
26
## Install NetworkManager
37

48
NetworkManager provides detection and configuration for systems to automatically connect to different wired and wireless networks.
59

6-
**Note:** Do not use SSH/remote desktop for these commands, as your network connection can become unavailable.
7-
810
```sh
911
sudo apt-get install network-manager
1012
sudo systemctl disable dhcpcd
@@ -26,14 +28,27 @@ With `nmcli`, you can also easily connect to a wifi network (if needed):
2628
sudo nmcli device wifi con "my-ssid" password "my-pass"
2729
```
2830

29-
## Install BlynkEdgent
31+
## Troubleshooting
32+
1. Make sure that your `wlan` interface is not configured via `/etc/network/interfaces`. NetworkManager ignores such interfaces.
33+
2. Check if your WiFi is blocked using `rfkill list`. Run `rfkill unblock wifi` to unblock it.
34+
3035

36+
## Install Edgent prerequisites
3137

3238
```sh
3339
pip3 install --upgrade https://github.com/vshymanskyy/nmcli/archive/master.zip
40+
pip3 install --upgrade RPi.GPIO
3441
```
3542

36-
## Troubleshooting
37-
1. Make sure that your `wlan` interface is not configured via `/etc/network/interfaces`. NetworkManager ignores such interfaces.
38-
2. Check if your WiFi is blocked using `rfkill list`. Run `rfkill unblock wifi` to unblock it.
43+
## Attach config reset button
44+
45+
Connect button between gpio16 and GND.
46+
Hold the button for 10 seconds to reset config.
47+
48+
## Run script manually
49+
50+
```
51+
pyhton3 beemate.py
52+
```
3953

54+
Alternatively, you can configure RPi to auto-run `main.py` on boot.

examples/Edgent_Linux_RPi/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
config = json.load(jsonFile)
2222
needToSave = False
2323
except:
24-
config = BlynkEdgent.provision(BLYNK_DEVICE_NAME, BLYNK_TEMPLATE_ID, BLYNK_FIRMWARE_VERSION, prefix="Beemate")
24+
config = BlynkEdgent.provision(BLYNK_DEVICE_NAME, BLYNK_TEMPLATE_ID, BLYNK_FIRMWARE_VERSION)
2525
needToSave = True
2626

2727
def reset_config():

0 commit comments

Comments
 (0)