Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 514d3f3

Browse filesBrowse files
committed
Sample Discovery and Monitor scripts
1 parent 7dc8ca4 commit 514d3f3
Copy full SHA for 514d3f3

File tree

Expand file treeCollapse file tree

3 files changed

+323
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+323
-0
lines changed

‎platform.txt

Copy file name to clipboardExpand all lines: platform.txt
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,40 @@ recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build
190190
recipe.size.regex=^(?:\.iram0\.text|\.iram0\.vectors|\.dram0\.data|\.flash\.text|\.flash\.rodata|)\s+([0-9]+).*
191191
recipe.size.regex.data=^(?:\.dram0\.data|\.dram0\.bss|\.noinit)\s+([0-9]+).*
192192

193+
## --------------------------------
194+
## Pluggable Discovery and Monitors
195+
## --------------------------------
196+
193197
## Required discoveries and monitors
194198
## ---------------------------------
195199
pluggable_discovery.required.0=builtin:serial-discovery
196200
pluggable_discovery.required.1=builtin:mdns-discovery
197201
pluggable_monitor.required.serial=builtin:serial-monitor
198202

203+
204+
## release.json definition for custom discoveries and monitors
205+
## -----------------------------------------------------------
206+
## "discoveryDependencies": [
207+
## { "packager": "espressif", "name": "espnow-discovery" }
208+
## ],
209+
## "monitorDependencies": [
210+
## { "packager": "espressif", "name": "espnow-monitor" },
211+
## { "packager": "espressif", "name": "espota-monitor" },
212+
## ]
213+
214+
## platform.txt definition for custom discoveries and monitors
215+
## -----------------------------------------------------------
216+
## pluggable_discovery.required.2=espressif:espnow-discovery
217+
## pluggable_monitor.required.espnow=espressif:espnow-monitor
218+
## pluggable_monitor.required.network=espressif:espota-monitor
219+
220+
## Demo Pluggable Discovery
221+
pluggable_discovery.espnow.pattern="{runtime.platform.path}/tools/espnow-discovery.py"
222+
223+
## Demo Pluggable Monitor
224+
pluggable_monitor.pattern.espnow="/Users/ficeto/Documents/Arduino/hardware/espressif/esp32/tools/espnow-monitor.py"
225+
226+
199227
## ------------------
200228
## Upload/Debug tools
201229
## ------------------

‎tools/espnow-discovery.py

Copy file name to clipboard
+151Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/opt/homebrew/bin/python3
2+
3+
import sys, os, time
4+
import logging
5+
6+
# HELLO <PROTOCOL_VERSION> "<USER_AGENT>"
7+
# {
8+
# "eventType": "hello",
9+
# "protocolVersion": 1,
10+
# "message": "OK"
11+
# }
12+
13+
# START
14+
# {
15+
# "eventType": "start",
16+
# "message": "OK"
17+
# }
18+
# {
19+
# "eventType": "start",
20+
# "error": true,
21+
# "message": "Permission error"
22+
# }
23+
24+
# STOP
25+
# {
26+
# "eventType": "stop",
27+
# "message": "OK"
28+
# }
29+
# {
30+
# "eventType": "stop",
31+
# "error": true,
32+
# "message": "Resource busy"
33+
# }
34+
35+
# QUIT
36+
# {
37+
# "eventType": "quit",
38+
# "message": "OK"
39+
# }
40+
41+
# LIST
42+
# {
43+
# "eventType": "list",
44+
# "ports": [
45+
# {
46+
# "address": <-- THE ADDRESS OF THE PORT
47+
# "label": <-- HOW THE PORT IS DISPLAYED ON THE GUI
48+
# "protocol": <-- THE PROTOCOL USED BY THE BOARD
49+
# "protocolLabel": <-- HOW THE PROTOCOL IS DISPLAYED ON THE GUI
50+
# "properties": {
51+
# <-- A LIST OF PROPERTIES OF THE PORT
52+
# }
53+
# },
54+
# {
55+
# ... <-- OTHER PORTS...
56+
# }
57+
# ]
58+
# }
59+
# {
60+
# "eventType": "list",
61+
# "error": true,
62+
# "message": "Resource busy"
63+
# }
64+
65+
# START_SYNC
66+
# {
67+
# "eventType": "start_sync",
68+
# "message": "OK"
69+
# }
70+
# {
71+
# "eventType": "start_sync",
72+
# "error": true,
73+
# "message": "Resource busy"
74+
# }
75+
# {
76+
# "eventType": "add",
77+
# "port": {
78+
# "address": "/dev/ttyACM0",
79+
# "label": "ttyACM0",
80+
# "properties": {
81+
# "pid": "0x804e",
82+
# "vid": "0x2341",
83+
# "serialNumber": "EBEABFD6514D32364E202020FF10181E",
84+
# "name": "ttyACM0"
85+
# },
86+
# "protocol": "serial",
87+
# "protocolLabel": "Serial Port (USB)"
88+
# }
89+
# }
90+
# {
91+
# "eventType": "remove",
92+
# "port": {
93+
# "address": "/dev/ttyACM0",
94+
# "protocol": "serial"
95+
# }
96+
# }
97+
98+
# Invalid commands
99+
# {
100+
# "eventType": "command_error",
101+
# "error": true,
102+
# "message": "Unknown command XXXX"
103+
# }
104+
105+
106+
107+
logging.basicConfig(filename=os.path.dirname(os.path.realpath(__file__))+'/pluggable.log', filemode='a+', encoding='utf-8', level=logging.DEBUG)
108+
log = logging.getLogger('espnow-discovery')
109+
110+
discovery_hello = False
111+
discovery_started = False
112+
discovery_sync = False
113+
114+
def send_msg(msg):
115+
sys.stdout.write(msg)
116+
sys.stdout.flush()
117+
log.debug("TX: %s" % msg)
118+
119+
if __name__ == "__main__":
120+
try:
121+
while True:
122+
for line in sys.stdin:
123+
line = line.rstrip()
124+
log.debug("RX: %s" % line)
125+
if line.startswith("HELLO 1"):
126+
discovery_hello = True
127+
send_msg('{"eventType": "hello", "protocolVersion": 1, "message": "OK"}')
128+
elif line.startswith("LIST"):
129+
send_msg('{"eventType": "list", "ports": [{"address": "aa:bb:cc:dd:ee:ff", "label": "ESP-NOW aa:bb:cc:dd:ee:ff", "protocol": "espnow", "protocolLabel": "ESP-NOW (WiFi)", "properties": {"channel": "1", "board": "esp32s2"}}]}')
130+
elif line.startswith("START_SYNC"):
131+
discovery_sync = True
132+
send_msg('{"eventType": "start_sync", "message": "OK"}')
133+
# time.sleep(5)
134+
send_msg('{"eventType": "add", "port": {"address": "aa:bb:cc:dd:ee:ff", "label": "ESP-NOW aa:bb:cc:dd:ee:ff", "protocol": "espnow", "protocolLabel": "ESP-NOW (WiFi)", "properties": {"channel": "1", "board": "esp32s2"}}}')
135+
elif line.startswith("START"):
136+
discovery_started = True
137+
send_msg('{"eventType": "start", "message": "OK"}')
138+
elif line.startswith("STOP"):
139+
discovery_started = False
140+
discovery_sync = False
141+
send_msg('{"eventType": "stop", "message": "OK"}')
142+
elif line.startswith("QUIT"):
143+
send_msg('{"eventType": "quit", "message": "OK"}')
144+
sys.exit(0)
145+
else:
146+
send_msg('{"eventType": "command_error", "error": true, "message": "Unknown command XXXX"}')
147+
148+
time.sleep(0.1)
149+
except Exception as e:
150+
sys.exit(1)
151+
sys.exit(0)

‎tools/espnow-monitor.py

Copy file name to clipboard
+144Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/opt/homebrew/bin/python3
2+
3+
import sys, os, time
4+
import logging
5+
6+
# HELLO <PROTOCOL_VERSION> "<USER_AGENT>"
7+
# {
8+
# "eventType": "hello",
9+
# "protocolVersion": 1,
10+
# "message": "OK"
11+
# }
12+
13+
# QUIT
14+
# {
15+
# "eventType": "quit",
16+
# "message": "OK"
17+
# }
18+
19+
# Invalid commands
20+
# {
21+
# "eventType": "command_error",
22+
# "error": true,
23+
# "message": "Unknown command XXXX"
24+
# }
25+
26+
# DESCRIBE
27+
# {
28+
# "eventType": "describe",
29+
# "message": "ok",
30+
# "port_description": {
31+
# "protocol": "serial",
32+
# "configuration_parameters": {
33+
# "baudrate": {
34+
# "label": "Baudrate",
35+
# "type": "enum",
36+
# "values": [
37+
# "300", "600", "750", "1200", "2400", "4800", "9600",
38+
# "19200", "38400", "57600", "115200", "230400", "460800",
39+
# "500000", "921600", "1000000", "2000000"
40+
# ],
41+
# "selected": "9600"
42+
# },
43+
# "parity": {
44+
# "label": "Parity",
45+
# "type": "enum",
46+
# "values": [ "N", "E", "O", "M", "S" ],
47+
# "selected": "N"
48+
# },
49+
# "bits": {
50+
# "label": "Data bits",
51+
# "type": "enum",
52+
# "values": [ "5", "6", "7", "8", "9" ],
53+
# "selected": "8"
54+
# },
55+
# "stop_bits": {
56+
# "label": "Stop bits",
57+
# "type": "enum",
58+
# "values": [ "1", "1.5", "2" ],
59+
# "selected": "1"
60+
# }
61+
# }
62+
# }
63+
# }
64+
65+
# CONFIGURE <PARAMETER_NAME> <VALUE>
66+
# {
67+
# "eventType": "configure",
68+
# "message": "ok"
69+
# }
70+
# {
71+
# "eventType": "configure",
72+
# "error": true,
73+
# "message": "invalid value for parameter baudrate: 123456"
74+
# }
75+
76+
# OPEN <CLIENT_TCPIP_ADDRESS> <BOARD_PORT>
77+
# {
78+
# "eventType": "open",
79+
# "message": "ok"
80+
# }
81+
# {
82+
# "eventType": "open",
83+
# "error": true,
84+
# "message": "unknown port /dev/ttyACM23"
85+
# }
86+
# {
87+
# "eventType": "port_closed",
88+
# "message": "serial port disappeared!"
89+
# }
90+
91+
# CLOSE
92+
# {
93+
# "eventType": "close",
94+
# "message": "ok"
95+
# }
96+
# {
97+
# "eventType": "close",
98+
# "error": true,
99+
# "message": "port already closed"
100+
# }
101+
102+
103+
104+
105+
logging.basicConfig(filename=os.path.dirname(os.path.realpath(__file__))+'/pluggable.log', filemode='a+', encoding='utf-8', level=logging.DEBUG)
106+
log = logging.getLogger('espnow-monitor')
107+
108+
monitor_hello = False
109+
monitor_open = False
110+
111+
def send_msg(msg):
112+
sys.stdout.write(msg)
113+
sys.stdout.flush()
114+
log.debug("TX: %s" % msg)
115+
116+
if __name__ == "__main__":
117+
try:
118+
while True:
119+
for line in sys.stdin:
120+
line = line.rstrip()
121+
log.debug("RX: %s" % line)
122+
if line.startswith("HELLO 1"):
123+
monitor_hello = True
124+
send_msg('{"eventType": "hello", "protocolVersion": 1, "message": "OK"}')
125+
elif line.startswith("DESCRIBE"):
126+
send_msg('{"eventType": "describe", "message": "ok", "port_description": {"protocol": "espnow", "configuration_parameters": {"baudrate": {"label": "Baudrate", "type": "enum", "values": ["9600", "19200", "38400", "57600", "115200", "230400", "460800", "921600"], "selected": "921600"}}}}')
127+
elif line.startswith("CONFIGURE "):
128+
send_msg('{"eventType": "configure", "message": "OK"}')
129+
elif line.startswith("OPEN"):
130+
monitor_open = True
131+
send_msg('{"eventType": "open", "message": "OK"}')
132+
elif line.startswith("CLOSE"):
133+
monitor_open = False
134+
send_msg('{"eventType": "close", "message": "OK"}')
135+
elif line.startswith("QUIT"):
136+
send_msg('{"eventType": "quit", "message": "OK"}')
137+
sys.exit(0)
138+
else:
139+
send_msg('{"eventType": "command_error", "error": true, "message": "Unknown command XXXX"}')
140+
141+
time.sleep(0.1)
142+
except Exception as e:
143+
sys.exit(1)
144+
sys.exit(0)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.