Skip to main content
All CollectionsConnect your Devices
Connect a FiPy Pycom Board to Ubidots
Connect a FiPy Pycom Board to Ubidots

Learn how to connect your FiPy Pycom Board to Ubidots and deploy IoT applications with ease!

Sergio M avatar
Written by Sergio M
Updated over a week ago

The Pycom team now delivers an IoT development board featuring WiFi, Bluetooth, LoRa, Sigfox and dual LTE-M (CAT M1 and NBIoT); one board to connect it all! 

The FiPy is perfectly formed board that is the the same sized unit as Pycom's other available boards WiPy, SiPy and LoPy

To connect this multi-connection board to Ubidots, continue reading for steps to setup over the following networks:

  •  WiFi

  • Sigfox

  • LoRaWAN

 

Requirements

Getting started with your FiPy

1. Hardware Setup

Before beginning, it is important check the resources below to ensure your board will be programmed correctly:

If this is your first time working with a Pycom board, we highly recommend you reference their getting started materials and then return to this guide for further instruction once you have become familiar.

2. Connect you FiPy over WiFi  

  • Setting up the project 

1. Create a new directory in the Pymakr called "pycom-wifi-ubidots" to manage the different codes and libraries for your project. 

2. In the the project "pycom-wifi-ubidots" we are going to manage the libraries and main/boot codes. Please reference and follow the structure below to build your project properly:

> pycom-wifi-ubidots
  - boot.py
  - main.py
  > lib
    -urequests.py

Based in the Pymakr plugin editor chose to configure your project, there will be different way to create files and directories. In the editor of your choice, create 2 new files boot.py and main.py plus 1 new directory called "lib" which will be used to manage all of the required libraries in your project.  

  • Now it is time to Code

  1. Copy and paste the library from this link into the "urequests.py" file within the "lib" directory. Once pasted, save your work

  2. Now copy and paste the code below into the "boot.py" file 

from machine import UART
import machine
import os

uart = UART(0, baudrate=115200)
os.dupterm(uart)

machine.main('main.py')

Don't forget save the "boot.py" file once pasted. 

3. Copy and paste the code below into the "main.py" file:  

from network import WLAN
import urequests as requests
import machine
from machine import Pin
import time

TOKEN = "Assign_your_ubidots_token" #Put here your TOKEN
DEVICE_LABEL = "fipy-pycom" # Assign the device label desire to be send
VARIABLE_LABEL = "sensor"  # Assign the variable label desire to be send
WIFI_SSID = "xxxxxxx" # Assign your the SSID of your network
WIFI_PASS = "xxxxxxx" # Assign your the password of your network
DELAY = 5  # Delay in seconds

adc = machine.ADC(bits = 12)    # create an ADC object
apin = adc.channel(pin='P16')   # create an analog pin on P16

wlan = WLAN(mode=WLAN.STA)
wlan.antenna(WLAN.INT_ANT)
wlan.connect(WIFI_SSID, auth=(WLAN.WPA2, WIFI_PASS), timeout=5000)

while not wlan.isconnected ():

    machine.idle()

print("Connected to Wifi\n")

# Builds the json to send the request

def build_json(variable, value):

    try:

        data = {variable: {"value": value}}

        return data

    except:

        return None

# Sends the request. Please reference the REST API reference https://ubidots.com/docs/api/

def sendData(device, variable, value):

    try:

        url = "https://industrial.api.ubidots.com/"

        url = url + "api/v1.6/devices/" + device

        headers = {"X-Auth-Token": TOKEN, "Content-Type": "application/json"}

        data = build_json(variable, value)

        if data is not None:

            print(data)

            req = requests.post(url=url, headers=headers, json=data)

            return req.json()

        else:

           pass

    except:

        pass

while True:

    value = apin() * 1.0

    sendData(DEVICE_LABEL, VARIABLE_LABEL, value)

    time.sleep(DELAY)

Once you've pasted the code, be sure to assign your Ubidots Token and the Wi-Fi credentials where indicated and save the code when finished. If you don't how find your Ubidots TOKEN, please reference this article

4. Once all 3 codes provided above are updated and saved to their respective folders, upload the project into the FiPy board by pressing the "Upload" button of the Pymakr Plugin. 

5. Then go to your Ubidots account to visualize the device you just created upon sending receiving the first dot of data.

3. Connect your FiPy over Sigfox

Please, reference to the following guide to get started with your FiPy board over Sigfox.

4. Connect your FiPy over LoRaWAN

Please, reference to the following guide to get started with your FiPy board over LoRaWAN.


IMPORTANT NOTE: No matter the board type you are using WiPy, SiPy, LoPy, or FiPy, the entire Pycom family coding to Ubidots is the same, needing only to apply the proper connection protocol based on your board's capabilities and your projects :)

5. Summary

The Pycom boards provide a nice way to quickly set up wireless networks and links for your sensors to the cloud. Covering Wi-Fi, Bluetooth, LoRa, Sigfox, and dual LTE-M (CAT M1 and NBIoT) plus the functionality of Pymakr allows users to switch between network communication protocols on-the-go without redoing the entire software credentials or firmware expectations.

Now it is time to create a dashboard to control and manage the variables of your Pycom device. To learn more about Ubidots widgets and events, check out these video tutorials to get your application up-and-running in no time!

Other readers have also found useful...

 


Did this answer your question?