Hello there,
I am currently working on a project that sends MQ-7 (Gas sensor) values to TTN using a dual channel gateway built from a dragino Lora Hat and a Raspberry pi3. While im waiting for my sensor to arrive from post i decided to write a program that will send random values that acts like my sensor to the TTN since it will be good for my project Blog. Unfortunately my program doesn’t seem to be working. I belive evrything in the program is correct but the device wont join TTN. There could be something wrong with my program but I don’t know what
from network import LoRa
import socket
import time
import ubinascii
import struct
import random
import time
from random import seed
from random import randint
COLOUR_BLACK = 0x000000
COLOUR_RED = 0xFF0000
COLOUR_GREEN = 0x00FF00
pycom.heartbeat(False)
pycom.rgbled(COLOUR_BLACK)
# Initialise LoRa in LORAWAN mode.
# Please pick the region that matches where you are using the device:
# Asia = LoRa.AS923
# Australia = LoRa.AU915
# Europe = LoRa.EU868
# United States = LoRa.US915
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
print("DevEUI: " + ubinascii.hexlify(lora.mac()).decode('utf-8').upper())
# create an OTAA authentication parameters
app_eui = ubinascii.unhexlify('xxxxxxxxxxxxxx')
app_key = ubinascii.unhexlify('xxxxxxxxxxxxxxxxxxxxxxxxxxxx')
# join a network using OTAA (Over the Air Activation)
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
while not lora.has_joined():
print('Not yet joined...')
pycom.rgbled(COLOUR_RED)
time.sleep(3)
#line.40
print("Joined network")
pycom.rgbled(COLOUR_GREEN)
# create socket to be used for LoRa communication
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
# configure data rate
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
# make the socket blocking
# (waits for the data to be sent and for the 2 receive windows to expire)
s.setblocking(True)
#define which port with the socket bind
s.bind(2)
#send some data
def send_level():
# seed random number generator
seed(1)
# generate some integers
for _ in range(10000000): #Fake sensor sends values till 10000000 to act as
# a infinite loop
value = randint(1, 12800) #12,800 is the highest level of CO
print('Sending CO level: {}'.format(value))
uplink_message = bytes([value])
s.send(uplink_message)
time.sleep(5) # 5 second delay
s.setblocking(False)
# get any data received...
data = s.recv(64)
print(data)
I recieve some errors such as…
Traceback (most recent call last):
File “”, line 40
IndentationError: unexpected indent
But when i check the line i cant seem to spot the error.
Any help or pointers will be much appriciated