we are beginners in this Lora technology.
We are trying to communicate Pycom Lopy4 and RAK7258 gateway using Lora.
The frequency used for testing was AU915.
No antenna was used and transmission power: 2dB
Spread factor: 7
The mode was LoraWAN.
And one more clarification also why the data received shows unconfirmed data. And is this packet missing is because of lower transmission power. We are not able to increase the power because we feel without the antenna chip may get damaged.
Measuring temperature by TMP36
from network import LoRa
from machine import Pin
adc = machine.ADC() # create an ADC object
apin = adc.channel(pin=Pin.exp_board.G3) # Lopy4 specific: (pin = ‘P16’) create an analog pin on P16 & connect TMP36
print(“Reading Moisture Sensor…”)
value = apin()
print(“ADC count = %d” %(value))
# LoPy has 1.1 V input range for ADC temp = ((value * 1100 ) / 4096 - 500) / 10 print("Temperature = %5.1f C" % (temp)) return temp
disable LED heartbeat (so we can control the LED)
set LED to red
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU915,tx_power=2)
app_eui = binascii.unhexlify(‘ADA4DAE3AC12676B’)
app_key = binascii.unhexlify(‘11B0282A189B75B0B4D2D8C7FA38548B’)
attempt join - continues attempts background
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
wait for a connection
print(‘Waiting for LoRaWAN network connection…’)
while not lora.has_joined():
# if no connection in a few seconds, then reboot
we’re online, set LED to green and notify via print
setup the socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
s.send(bytes([0x01, 0x02, 0x03]))
get any data received…
#data = s.recv(64)
limit to 200 packets; just in case power is left on
# take temp measurment, turn the temp blue when measuring
temp = temp_measure()
# encode the packet, so that it's in BYTES (TTN friendly) # could be extended like this struct.pack('f', temp) + struct.pack('c',"example text") # 'h' packs it into a short, 'f' packs it into a float, must be decoded in TTN packet = ustruct.pack('f', temp) # send the prepared packet via LoRa s.send(packet) # example of unpacking a payload - unpack returns a sequence of #immutable objects (a list) and in this case the first object is the only object print ("Unpacked value is:", ustruct.unpack('f',packet)) # check for a downlink payload, up to 64 bytes rx_pkt = s.recv(64) # check if a downlink was received if len(rx_pkt) > 0: print("Downlink data on port 200:", rx_pkt) pycom.rgbled(0x7f0000) utime.sleep(40)
Thanks in advance for your support.