forked from LucasCoelho14/EmbaubaSAT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodiguin.txt
48 lines (43 loc) · 1.11 KB
/
codiguin.txt
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
import json
import spidev
import time
#definição dos pinos do raspberry (não necessário por enquanto)
fifoptraddr = 0x00
localtxaddr = 0xBB
destino = 0xBC
#defina a função de setar a frequencia do Lora
def set_freq(f):
i = int(f * 16384.) # choose floor
msb = i // 65536 #msb
i -= msb * 65536 #
mid = i // 256 #mid
i -= mid * 256
lsb = i
return Lora.xfer([ 0x06 | 0x80, msb, mid, lsb])
#Constantes que representam o modo de operação
SLEEP = 0x80
STDBY = 0x81
FSTX = 0x82
TX = 0x83
FSRX = 0x84
RXCONT = 0x85
RXSINGLE = 0x86
CAD = 0x87
FSK_STDBY= 0x01
Lora = spidev.SpiDev()
Lora.open(0,0)
set_freq(915.0)
Lora.xfer2([(0x01| STDBY)])
Lora.xfer2([0x0E | 0x80, localtxaddr])
Lora.xfer2([(fifoptraddr) | 0x80, localtxaddr])
while True:
dados = "oi, esp32"
payload = bytes(dados2, 'utf-8')
payload_length = [len(payload)]
Lora.xfer2([0xBC])
Lora.xfer([localtxaddr])
Lora.xfer2(payload_length)
Lora.xfer2(payload)
Lora.xfer2([(0x01)&0x7F | 0x83])
print("Enviando...\n")
time.sleep(2)