Skip to main content
All CollectionsConnect your Devices
Connect the Blues Wireless Sparrow to Ubidots
Connect the Blues Wireless Sparrow to Ubidots

This article explores how to set up your Sparrow development kit to send data to Ubidots

Sergio M avatar
Written by Sergio M
Updated over 2 months ago

Component 1(1).png

The Sparrow, by Blues Wireless, is a kit composed of a gateway and a couple of nodes that, each, can communicate to the gateway through LoRa. Its most remarkable feature is the ease with which the user can quickly set up a project without coding at all.

image 4(2).png

Requirements

Table of Contents

  1. Setting up the Hardware

  2. Set up Notehub

  3. Pair the Notecard with the Reference Nodes

  4. Visualizing the Events on Notehub

  5. Create the Function to receive the data from Notehub

  6. Route data from Notehub to Ubidots

  7. Visualize the data on Ubidots

  8. Feedback, suggestions, and related articles

1. Setting up the Hardware

  • Remove the screws from the back of each node that you wish to configure.

  • Insert two AAA batteries. For the moment, leave the nodes without the enclosure.

image 5.png
  • Connect your Essentials Board to your Notecarrier-A using the included Qwiic cable.

Component 2.png
  • Make sure that the DIP switch on the Notecarrier-A is set to 3V3.

image 7.png
  • Ensure the DIP switches on the Essentials Board are all pointing towards 1,2,3,4.

image 8.png
  • Connect the Notecarrier-A board to the PC by using the provided micro USB to USB-A data cable. After doing so, you should see the green LED is turned on both the Notecarrier-A and the Essentials Board.

Component 4(1).png

2. Set up Notehub

  • Log in to your Notehub account.

  • Once on your Notehub dashboard, click the Create Project button.

  • Fill in the following fields according to:

    • Billing account: Select or create an account for your billing.

    • Project name: Set any name that you want for your project.

    • ProductUID prefix: This will be set by default with the username and organization provided when your Notehub account was created.

    • ProductUID: This is the suffix for your current project. You can set any that you want, however, it is advised to set it the same as your project’s name.

  • Click the Create Project button to create the project.

Component 3.png
  • Copy the project’s ProductUID.

Component 5.png
  • Head to dev.Blues.

  • Click where the Disconnected message is being displayed.

Component 6.png
  • Click the USB Notecard button below the Connect a Notecard message.

  • Select the port to which your device is connected to.

  • Click the Connect button.

Component 7.png
  • Once done, a serial terminal will open on your browser.

  • Run the following command making sure to replace com.your-company.your-name:your_product for your ProductUID obtained in previous steps.

{"req":"hub.set", "product":"com.your-company.your-name:your_product","mode":"continuous"}

  • The device shall respond with an empty JSON object:

Component 8.png
  • Connect the Notecard to your Wi-Fi by running the following command, making sure to replace “ssid name” and “password” with your corresponding credentials:

{"req":"card.wifi","ssid":"<ssid name>","password":"<password>"}
Component 9.png

3. Pair the Notecard with the Reference Nodes

  • Press and release the Pair button on the Essentials Board and then press the same button on the Reference Node.

  • While pairing, both the Essentials Board and Reference Nodes should show a solid blue LED light, which indicates the devices are in pairing mode.

  • When the pairing process is completed, you’ll see red, green, and blue LED flashing on the Essentials Board.

image 21.png

Pro Tip: Pairing LoRa devices works best if they're separated from each other, as on opposite sides of the table.



4. Visualizing the Events

  • Head back to Notehub.

  • Click the Events option.

Component 10.png
  • On the Events page you will be able to see all of the events regarding to each Reference Node.

image 23.png

5. Create the Function to receive the data from Notehub

  • Go to your Ubidots account.

  • Click on the Devices → Functions.

  • Create a new Function with the following parameters:

    • Name: set any name that you want

    • Method: POST

    • Runtime: For this example, Python 3.7 was chosen, however, you can select the one that you feel most comfortable with

    • Token: Select the Ubidots token that you want to use for this particular application

  • Edit the Function’s code. Delete everything and paste the following:

import requests

BASE_URL = "https://industrial.api.ubidots.com"
TOKEN = 'BBFF-WEplLU79KGBNVrLUt3lGEFIuOviAOg'

def main(args):

print(args)

device_label_map = {
"203733583236500300360033":"reference-node-1",
"203733583236500300260033":"reference-node-2",
}

functions_map = {
"air.qo": air,
"motion.qo": motion,
"sensors.db": sensors,
"_health.qo":health
}


file_data = args["file"]
payload_type = ""

if(file_data == "_health.qo"):
device_label = args["body"]["text"].split(" ")[0]
device_label = device_label_map[device_label]
payload_type = file_data

elif(file_data == "sensors.db"):
device_label = device_label_map[args["note"]]
payload_type = file_data

elif(file_data == "_session.qo"):
return {"status":200, "text":"session.qo report cotinuous connectio mode report"}

else:
file_number_index = 0
payload_type_index = 1
file_data = args["file"].split("#")
device_label = device_label_map[file_data[file_number_index]]
payload_type = file_data[payload_type_index]


# Get the timestamp
timestamp = args.get("when", None)
timestamp = timestamp * 1000 if timestamp is not None else None

payload = functions_map[payload_type](args)

res = send_data(device_label, payload, TOKEN, **{"timestamp":timestamp})
return {"status": res.status_code, "text": res.text}


def health(args):
args = args["body"]
ret = {"button-status":
{
"value":1,
"context":"pressed"
}
}
return ret

def air(args):
args = args["body"]
ret = { "humidity": args["humidity"],
"pressure": args["pressure"],
"temperature": args["temperature"],
"voltage": args["voltage"]
}
return ret

def motion(args):
args = args["body"]
ret = { "motion-count": args["count"],
"motion-total": args["total"]
}
return ret

def sensors(args):
args = args["body"]
ret = { "voltage":
{
"value":args["voltage"],
"context":
{
"gateway_rssi": args["gateway_rssi"],
"gateway_snr": args["gateway_snr"],
"lost": args["lost"],
"received": args["received"],
"sensor_ltp": args["sensor_ltp"],
"sensor_rssi": args["sensor_rssi"],
"sensor_snr": args["sensor_snr"],
"sensor_txp": args["sensor_txp"],
}
}
}
return ret

def send_data(device, payload, token, **params):
url = f"{BASE_URL}/api/v1.6/devices/{device}/"
headers = {"X-Auth-Token": token, "Content-Type": "application/json"}
res = make_request("post", url, headers=headers, params=params, body_json=payload, attempts=5)
return res

def make_request(
method,
url,
params=None,
headers=None,
body=None,
body_json=None,
attempts=1,
timeout=10,
):
"""
Function to make a request with timeout and retries
"""

req_session = requests.Session()
req_adapter = requests.adapters.HTTPAdapter(max_retries=attempts)
req_session.mount("https://", req_adapter)

response = req_session.request(
method=method.upper(),
url=url,
params=params,
headers=headers,
data=body,
json=body_json,
timeout=timeout,
)

req_session.close()
response.raise_for_status()

return response

  • Copy the Function’s HTTPs Endpoint URL to your clipboard. This will be needed later.

6. Route data from Notehub to Ubidots

  • Go to Notehub.

  • Click on the Routes option.

  • Click Create Route.

Component 11.png
  • Click the Select button for the General HTTP/HTTPS Request/Response option.

Component 12.png

Fill in the following field according to:

  • Route name: any name that you want to use for this route

  • URL: your Function’s HTTPs Endpoint URL obtained in the previous section

  • HTTP Headers: select Additional Headers. Then:

    • Set the Header name to “X-Auth-Token”

    • Set the Header value to your Ubidots token that you want to use for this application. It has to be the same as the one that you selected for the Function in the previous section.

Other settings such as Rate limit, Timeout, and Filters were left on their default values, however, you can change these settings according to your requirements.

  • Click the Create Route button to save these settings and create the route.

Component 13.png

7. Visualize the data on Ubidots

  • Head back to your Ubidots account → Devices.

  • If you have been following this article’s nomenclature, you should be able to see two new devices, “reference-node-1” and “reference-node-2”.

image 28.png

8. Feedback, suggestions, and related articles

Feel free to post questions or suggestions in our community portal, or contact us via support@ubidots.com.

Other users also found helpful...

Did this answer your question?