-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcode-text receiver.py
49 lines (43 loc) · 1.32 KB
/
code-text receiver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#rename to code.py Put This code into another Circuitpython microcontroller
#type MODE+TEST
#type AT+TEST
#monitor that the message is received in HEX and converted into String
import board
import busio
import digitalio
import time
import supervisor
import binascii
import re
uart = busio.UART(board.D0, board.D1, baudrate=9600)
get_input = True
message_started = False
message_print = []
allstring = ""
printshow = False
while True:
if supervisor.runtime.serial_bytes_available:
allstring=""
userinput = input().strip()
b = bytes(userinput, 'utf-8')
uart.write(b)
continue
byte_read = uart.readline()# read up to 32 bytes
if byte_read != None:
allstring += byte_read.decode()
printshow = True
else:
if printshow == True:
if allstring != "":
print(allstring)
left ='"3C'
right ='3E"'
try:
b =allstring[allstring.index(left)+len(left):allstring.index(right)]
print(binascii.unhexlify(b).decode('utf8'))
#print(b)
except ValueError:
print(ValueError)
pass
allstring=""
printshow ==False