Digi-Key Weather Center XBee3 Gateway Configuration

Created by Robert Nelson, last modified on Apr 20, 2020

image

Introduction

This page will show you a step-by-step procedure on how we configured our XBee3 Zigbee 3.0 network at Digi-Key: LIVE DATA

Hardware Requirements

XBee End Device:

XBee Gateway:

Gateway Server:

Software:

XBee Network Design

Product Family XB3-24
Function Set Digi XBee3 Zigbee 3.0
Firmware version 1009
Network PAIN ID 5432

End Device XBee:

XBee End Device:

Software:

XCTU Configuration

AT Commands Parameter Description
ID Extended PAN ID 5432 The preconfigured Extended PAN ID used when forming or joining a network.
JN Join Notification 1 Broadcast Join Notification upon successful join attempt.
KY Link Key 00
NK Trust Center Network Key 00
NI Node Identifier Power_Controller The node identifier is a user-defined name or description of the device.
BD UART Baud Rate 57600 [6] This command configures the serial interface baud rate for communication between the UART port of the device and the host.
AP API Enable MicroPython REPL [4] API enabled (operate in Micropython mode)
PS MicroPython Auto Start Enable [1] Run stored Python code at startup.
FK File System Public Key Solar_Project_public_key.pem
D1 DIO1/AD1 Configuration I2C SCL [6] Application uses I2C to talk to sensors
P1 DIO11 Configuration I2C SDA [6] Application uses I2C to talk to sensors

Application

This devices reads a 4 INA219 Current sensors, a quick example application is show in this code block, but the full application can be found here:

from ina219 import INA219
from machine import I2C
import sys
import xbee
import time
 
print("#Booting Up...")
 
# Instantiate an I2C peripheral.
i2c = I2C(1)
for address in i2c.scan():
    print("- I2C device found at address: %s" % hex(address))
 
while xbee.atcmd("AI") != 0:
    print("#Trying to Connect...")
    time.sleep(0.5)
 
print("#Online...")
 
TARGET_64BIT_ADDR = b'\x00\x13\xA2\x00\x41\xA7\xAD\xBC'
 
def read_battery():
    try:
        battery_voltage = str(battery_ina.voltage())
        battery_current = str(battery_ina.current())
        print_battery = "Battery:" + time_snapshot + ":BusVolt:" + battery_voltage + "V:Current:" + battery_current + "mA:#"
    except:
        print_battery = "Battery:" + time_snapshot + ":BusVolt:INVALID:Current:INVALID:#"
        print("INA219:0x44: Battery read failed...")
 
    try:
        xbee.transmit(TARGET_64BIT_ADDR, print_battery)
    except:
        print("XBee: Battery TX Failed...")
 
 
battery_ina = INA219(0.1, I2C(1), 0x44)
try:
    print("INA219:0x44: Configuring Battery...")
    battery_ina.configure_32v_2a()
except:
    print("INA219:0x44: Battery Missing...")
 
while True:
    time_snapshot = str(time.ticks_cpu())
    read_battery()
    time.sleep(6)

Data Packet:

Battery:806294605:BusVolt:13.188V:Current:25.0mA:#

Coordinator XBee:

XBee Gateway:

Software:

XCTU Configuration

AT Commands Parameter Description
CE Device Role Form Network [1] Form Network (SM must be 0 to set CE to 1)
ID Extended PAN ID 5432 The preconfigured Extended PAN ID used when forming or joining a network.
KY Link Key 00
NK Trust Center Network Key 00
NI Node Identifier Network_Gateway The node identifier is a user-defined name or description of the device.
BD UART Baud Rate 57600 [6] This command configures the serial interface baud rate for communication between the UART port of the device and the host.
AP API Enable MicroPython REPL [4] API enabled (operate in Micropython mode)
PS MicroPython Auto Start Enable [1] Run stored Python code at startup.
FK File System Public Key Solar_Project_public_key.pem

Application

This device just runs as an echo server, all data it receives over the ZigBee network is echoed back over the serial port to the end server (BeagleBone Green in this example), with the FROM address pre-pended to the line,

import xbee
import time
 
print("#Booting Up...")
 
while xbee.atcmd("AI") != 0:
    print("#Trying to Connect...")
    time.sleep(0.5)
 
print("#Online: Waiting for XBee messages...")
 
while True:
    received_msg = xbee.receive()
    if received_msg:
        # Get the sender's 64-bit address and payload from the received message.
        sender = received_msg['sender_eui64']
        payload = received_msg['payload']
        print("MsgFrom:%s:%s" % (''.join('{:02x}'.format(x).upper() for x in sender), payload.decode()))

Data Packet:

MsgFrom:0013A20041A7AE31:Battery:806294605:BusVolt:13.188V:Current:25.0mA:#

Gateway Server:

Gateway Server:

Application

The Gateway Server is connected to XBee over USB, we need to configure the Serial port with stty. To parse the raw serial data, we use a python application called Grabserial, from which we grab the start of frame: “MsgFrom:” and end of frame “:#”. Attached is a quick echo example to accomplish this, the full version is available here.

#!/bin/bash
 
stty -F /dev/ttyUSB0 raw speed 57600 &> /dev/null
 
# Loop
while [ 1 ];
do
    READ=`grabserial -d /dev/ttyUSB0 -b 57600 -m "MsgFrom:" -q ":#"`
    echo "[$READ]:[`date`]"
    done
}

Data Packet:

[MsgFrom:0013A20041A7AE31:Battery:806294605:BusVolt:13.188V:Current:25.0mA:#]:[Mon Apr 20 02:05:43 UTC 2020]