DSC_0235Source LoPy

 
——————————————boot.py———————————
from machine import UART
import machine
import os
uart = UART(0, baudrate=115200)
os.dupterm(uart)
machine.main(‘main.py’)

——————————————loop.py————————————–
from machine import Pin
while True:
p_out = Pin(‘P9’, mode=Pin.OUT)
p_out.value(1)
p_out.value(0)
p_out.toggle()
p_out(True)
# make “P10“ an input with the pull-up enabled
p_in = Pin(‘P11’, mode=Pin.IN, pull=Pin.PULL_UP)
print(p_in()) # get value, 0 or 1
#while True:
# print(‘loop’)

—————————————-main.py————————————
from network import LoRa
import socket
import binascii
import struct
import time
## Initialize LoRa in LORAWAN mode.
#lora = LoRa(mode=LoRa.LORAWAN)
lora = LoRa(mode=LoRa.LORAWAN, frequency=868000000)
# create an ABP authentication params
dev_addr = struct.unpack(“>l”, binascii.unhexlify(‘XX XX XX XX’.replace(‘ ‘,”)))[0]
nwk_swkey = binascii.unhexlify(‘XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX’.replace(‘ ‘,”))
app_swkey = binascii.unhexlify(‘XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX’.replace(‘ ‘,”))
# join a network using ABP (Activation By Personalization)
lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
# create a LoRa socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
# set the LoRaWAN data rate
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
# make the socket non-blocking
s.setblocking(False)
#s.send(bytes([0x31, 0x32]))
while True:
s.send(’11’)
time.sleep(60)
# get any data received…
data = s.recv(64)
print(data)
print(‘Message send..’)

 
 
/// this source missed the input pin data. soon i will finx it on the site.