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.
Requirements
A Blues Wireless NoteHub account.
A Blues Wireless Sparrow Kit.
An Ubidots account.
Table of Contents
Setting up the Hardware
Set up Notehub
Pair the Notecard with the Reference Nodes
Visualizing the Events on Notehub
Create the Function to receive the data from Notehub
Route data from Notehub to Ubidots
Visualize the data on Ubidots
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.
Connect your Essentials Board to your Notecarrier-A using the included Qwiic cable.
Make sure that the DIP switch on the Notecarrier-A is set to 3V3.
Ensure the DIP switches on the Essentials Board are all pointing towards 1,2,3,4.
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.
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.
Copy the project’s ProductUID.
Head to dev.Blues.
Click where the Disconnected message is being displayed.
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.
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:
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>"}
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.
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.
On the Events page you will be able to see all of the events regarding to each Reference Node.
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.
Click the Select button for the General HTTP/HTTPS Request/Response option.
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.
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”.
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...