With LoRa, Wifi and BLE ,the LoPy is the only triple bearer MicroPython enabled micro controller on the market today – the perfect enterprise grade IoT platform for your connected Things. With the latest Espressif chipset the LoPy offers a perfect combination of power, friendliness and flexibility.

For more information just click here.

Requirements

  • LoPy Board.
  • Expansion Board.
  • Cable micro-USB
  • MultiTech MultiConnect Conduit AEP previously configured with the Ubidots LoRaWAN network server. If you don’t already have it, just click here.

Get started with your LoPy

1. Hardware set up.

On the following link you will find all the configurations that you have to do before start with your LoPy and Ubidots. Take care on all of it.

2. Connecting your board using Pymakr

To make it as easy as possible, the Pycom Team developed Pymakr, a tool that will allow you to connect to and program your Pycom devices. You can download Pymakr from here.

If you have any trouble connecting over USB using pymakr, make sure you have the proper  FTDI drivers installed.

3. Initial configuration:

  • Connect your computer to the WiFi network named after your board (e.g. lopy-wlan-xxxx, wipy-wlan-xxxx). The password is www.pycom.io
  • Open Pymakr.
  • In the menu, go to Settings > Preferences (Pymakr > Preferences).
  • In the left list look for Pycom Device.
  • For device, type down 192.168.4.1. The default username and password are micro and python, respectively.
  • Click OK

Pymakr also supports wired connections. Instead of typing the IP address, you can click on the combo box arrow and select the proper serial port from the list.

That’s it for the first time configuration. In the lower portion of the screen, you should see the console, with the connection process taking place. At the end of it, you’ll get a ‘connected’ message and a colored >>> prompt, indicating that you are connected:

Connect to Ubidots

1.- Log in to your Ubidots account.

2.- Select Devices and click on Add Device.

3.- Once you created the device select Enable LoRa.

For the auth (Over-The-Air Activation - OTAA) you will have to assign the following parameters to the code AppEUI, AppKey, DevEUI.

  • Device EUI (DevEUI): The DevEUI identifies the device on the LoRaWAN network during the JOIN request. This is assigned to the device by the chip manufacturer. You will be able to know the DevEUI through Pymakr console, just write the following commands.

Getting the DevEUI

>>> import network
>>> from network import LoRa
>>> import binascii
>>> binascii.hexlify(network.LoRa().mac())
b'70b3d5100046a40e'

The LoPy let’s you set the DevEUI if you need or desire.

  • Application EUI (AppEUI): The AppEUI identifies the application during the JOIN request. This will be generated automatically.
  • Application key (AppKey): The AppKey encrypts the data during the JOIN request. This will be generated automatically.

4.- You will see a windows with the parameters that you need to assign on the code.

Program you LoPy

1.- Open the Pymakr and copy the following code.

2.- Once you have copied the code you must assign your AppEUI, AppKey, DevEUI previously assigned to your account.

3.- Verify the connection of you LoPy on the console.

4.- Now it’s time to run the code at the top right of the Pymakr, and check the results on the console.

Code


from network import LoRa
import socket
import time
import binascii
import utime

def select_subband(lora, subband):
    if (type(subband) is int):
        if ((subband<1) or (subband>8)):
            raise ValueError("subband out of range (1-8)")
    else:
        raise TypeError("subband must be 1-8")

    for channel in range(0, 72):
        lora.remove_channel(channel)

    index = (subband-1)*8
    for channel in range(0, 7):
        lora.add_channel(channel, frequency=902300000+index*200000, dr_min=0, dr_max=3)
        index+=1

    index = (subband-1)*8
    for channel in range(8, 15):
        lora.add_channel(channel, frequency=902300000+index*200000, dr_min=0, dr_max=3)
        index+=1

    index = (subband-1)*8
    for channel in range(16, 23):
        lora.add_channel(channel, frequency=902300000+index*200000, dr_min=0, dr_max=3)
        index+=1

    index = (subband-1)*8
    for channel in range(24, 31):
        lora.add_channel(channel, frequency=902300000+index*200000, dr_min=0, dr_max=3)
        index+=1

    index = (subband-1)*8
    for channel in range(32, 39):
        lora.add_channel(channel, frequency=902300000+index*200000, dr_min=0, dr_max=3)
        index+=1

    index = (subband-1)*8
    for channel in range(40, 47):
        lora.add_channel(channel, frequency=902300000+index*200000, dr_min=0, dr_max=3)
        index+=1

    index = (subband-1)*8
    for channel in range(48, 55):
        lora.add_channel(channel, frequency=902300000+index*200000, dr_min=0, dr_max=3)
        index+=1

    index = (subband-1)*8
    for channel in range(56, 63):
        lora.add_channel(channel, frequency=902300000+index*200000, dr_min=0, dr_max=3)
        index+=1

    index = (subband-1)*8
    for channel in range(64, 71):
        lora.add_channel(channel, frequency=902300000+index*200000, dr_min=0, dr_max=3)
        index+=1

lora = LoRa(mode=LoRa.LORAWAN, adr=False, public=True, tx_retries=0)

sb = 1 #Change to desired conduit frequency sub-band

select_subband(lora,sb)

# assign your AppEUI, AppKey, DevEUI
app_eui = binascii.unhexlify('ff ff ba 78 20 0c c2 ee'.replace(' ',''))
app_key = binascii.unhexlify('12 67 ad a4 da e3 ac 12 67 6b ad da e3 ac ff ff'.replace(' ',''))
dev_eui = binascii.unhexlify ('b1 17 11 b5 3d ec b3 44'.replace(' ',''))  

# create an OTAA authentication (DevEUI, AppEUI, AppKey)
auth =(dev_eui, app_eui, app_key)

# create an OTAA authentication (AppEUI, AppKey)
#auth=(app_eui, app_key)

# join a network using OTAA (Over the Air Activation)
lora.join(activation=LoRa.OTAA, auth=auth, timeout=0)
print("Joined...")

while not lora.has_joined():
    time.sleep(5)
    print('Not yet joined on frequency sub-band '+str(sb)+'...')

s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setblocking(False)
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 3)

pressure = 1    

while lora.has_joined():
    payload = '{"pressure":'+str(pressure)+',"time":'+str(utime.time())+'}'
    print(payload)
    s.send(payload)
    time.sleep(6)

    pressure +=1

    if pressure > 100:
        pressure = 1

Results

As you may see, we just send time and pressure data to Ubidots using LoRaWan in just a few minutes.

Did this answer your question?