IQRF Dev Board & Gateway

In this post we will show you how to create gateway based IQRF network. Gateway connects whole IQRF mesh and propagates nodes data to internet. Gateway in IQRF world is something like Router in Wifi world.

IQRF gateway

IQRF strategy is to provide inter-operable gateway which means that youi can download IQRF Gateway Daemon software from IQRF which makes gateway from any computer e.g. Raspberry, UP2 board, Banana, and more…

You can anyway buy ready to go IQRF gateway on IQRF marketplace, e.g. AuroraHub IoT Gateway. Let’s go with this option.

Prepare gateway

Take your gateway and connect its ethernet connector with your Wifi router. Then power gateway up.

Now go to your Wifi router and get IP address of the gateway. Put this IP to your browser and you should see gateway configuration application.

Username and password is iqrf:iqrf or anything else that you got with your new gateway. This takes you to Dashboard screen. The gateway is now ready for use, so let’s start with building IQRF network.

Configure Gateway

First of all please set up an Access password. Go to IQRF network/TR configuration and then Security tab. Fill out your password and click Set Access password. This password we will use for any end noude connecting to the IQRF network.

Program end nodes

Our end node will be IQRF Development board. For programming of end nodes we will use CK-USB-04A programmer connected to USB and IQRF IDE for software upload.

Assemble IQRF Development Board, before that ensure JP6=OFF (battery connection) and JP1=OFF (Power to transceiver). Then insert battery and IQRF transceiver to board.

Now connect IQRF dev Board to CK-USB-04A programmer as shown in the picture. You can wire it yourself or use programming cable you’ve got with IQRF Dev board.

Make sure JP1=OFF and JP6=OFF on the board and connect connect programmer to USB of your computer. Open IDE and double-click DPA-config.xml. Go to Security tab and enter the same Access password you’ve entered into gateway above.

The OS and DPA settings keep the same as in the pictures below.

Finally click Upload. Close DPA config dialogue, make sure you have checked DPA-Node-STD-… under Plug-ins in Project window and pres F5 to upload all checked files.

Unplug USB programmer and IQRF Development Board. Now power up standalone IQRF Development board by JP6=ON and also power up IQRF transciever by JP1=ON. Now LD3 must be flashing. It indicated readiness for bonding to gateway.

If the LD3 is not flashing, then you have to unbond this board. We suggest to do it in hardware way:

Connect EQ12 and GND, then shortly remove JP1 and return it. Then green LD2 is ion, once it turns off release EQ12 and GND. Then LD3 starts flashing.

Bond end nodes

Now go back to gateway management and open IQRF network / Network manager.

Check Auto address option and click Bond Node. Now you have about 20sec for connection of EQ12 and GND on IQRF Dev board. Connect these pins just shortly. We suggest to prepare for this a jumper switch before pressing Bond node. Shortly after release of pins you should get a message about successful bonding of node.

Now go down and click Discovery button.

Now your device is bonded to IQRF mesh network and ready for use. You can check it when you see newly added symbol to proper address of this device.

Check operability of end nodes

Now we will turn LD2 on. Go to IQRF network / Send DPA packet and populate LED button and choose Set LEDG on.

This is a macro creating specific DPA message. Check Set own NADR which is an address of end node in network and specify NADR=1 as this address has been assigned to our IQRF dev boar during bonding procedure.

Then click Send an LD2 on the board is on. Similar way you can turn the LED off.

Congratulations! Your first end node is working with your gateway.

Notice: You can anytime turn board off via JP6=OFF and then turn it on. In this case you do not have to repeat any configuration steps since turn development board on always gets board back to ready state.

Manage device from your software

The most beautiful thing on IQRF gateways is that IQRF Tech keeps them inter-operable which means that gateway software provides JSON API which can be used in your software.

Actually you can find open Websocket channel at port :1338 and therefore you can freely communicate with gateway at address ws://IP-address:1338.

Now let’s try to manage embedded LD2 and LD3 on IQRF Dev board programatically. In Python script we will open Websocket channel and send commands switching LEDs on/off.

Prerequisities:

  • Install Python 3.6
  • Install $ pip install websockets
# 
# Copyright Logimic,s.r.o., www.logimic.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import asyncio
import websockets
import json
import time

# This is IQRFBB-10 node address in IQRF network
boardAddr = 3

# JSON messages by "https://docs.iqrfsdk.org/iqrf-gateway-daemon/api.html"
LEDR_ON = {
  "mType": "iqrfEmbedLedr_Set",
  "data": {
    "msgId": "testEmbedLedr",
    "req": {
      "nAdr": boardAddr,
      "param": {
        "onOff": True
      }
    },
    "returnVerbose": True
  }
}

LEDR_OFF = {
  "mType": "iqrfEmbedLedr_Set",
  "data": {
    "msgId": "testEmbedLedr",
    "req": {
      "nAdr": boardAddr,
      "param": {
        "onOff": False
      }
    },
    "returnVerbose": True
  }
}

LEDG_ON = {
  "mType": "iqrfEmbedLedg_Set",
  "data": {
    "msgId": "testEmbedLedr",
    "req": {
      "nAdr": boardAddr,
      "param": {
        "onOff": True
      }
    },
    "returnVerbose": True
  }
}

LEDG_OFF = {
  "mType": "iqrfEmbedLedg_Set",
  "data": {
    "msgId": "testEmbedLedr",
    "req": {
      "nAdr": boardAddr,
      "param": {
        "onOff": False
      }
    },
    "returnVerbose": True
  }
}

async def hello():
    # Connect websockets
    async with websockets.connect(
            'ws://localhost:1338') as websocket:

        # RED LED ON
        await websocket.send(json.dumps(LEDR_ON))
        print(f"Sent > {LEDR_ON}")

        response = await websocket.recv()
        print(f"Received < {response}")

        # Wait 2 sec
        time.sleep(2)

        # RED LED OFF
        await websocket.send(json.dumps(LEDR_OFF))
        print(f"Sent > {LEDR_OFF}")

        response = await websocket.recv()
        print(f"Received < {response}")        

        # GREEN LED ON
        await websocket.send(json.dumps(LEDG_ON))
        print(f"Sent > {LEDG_ON}")

        response = await websocket.recv()
        print(f"Received < {response}")        

        # Wait 2 sec
        time.sleep(2)

        # GREEN LED OFF
        await websocket.send(json.dumps(LEDG_OFF))
        print(f"Sent > {LEDG_OFF}")

        response = await websocket.recv()
        print(f"Received < {response}")            

asyncio.get_event_loop().run_until_complete(hello())

This scripts turns LD3 for 2sec and then LD2 for 2sec. These sent and received JSON API messages are also written to console.

Best practice

Since IQRF Development Board has been designed with standalone cell battery for design low-power consumption project, we strongly suggest to switch powering of board to micro-USB instead battery during any testing and development activities. Simply set JP6=OFF and connect micro USB to any power.