How to create your own Network to integrate with TagoIO

How to create your own Network to integrate with TagoIO

This is a quick tutorial that shows how to create a Network for your devices using TagoIO. By creating your own network you will be able to push data to TagoIO in the correct device based on it’s serial number, using your own protocol. There are several Networks available for you to use (learn about current Networks here), if you need something that is not in the list you can build yours.

By following all the steps in this article you will end up with:

  • An network capable of integrate your sensors to TagoIO, using your own protocol.
  • A connector that makes use of the network you created.
  • A middleware server in TCP/IP protocol, that you can use as example to build your own.

Creating the network

First you need to access the Integrations menu in the top right corner. Now go to Network > Add network and create the Network.

The edit page should show up, here you can personalize your Network as you like. We’re going to set the serial option on the right as required and set also the format to our serial to be like “000-000-000”.

Now create and copy the token in the token menu, we’ll need that later.

Setting up a connector

For the network to work properly a connector is needed. To create a connector go back to Integrations menu and create a connector instead. In the Add connector form, select the created network.

Having done that, you will be able to see your Network in the add new device menu.
Create a device with a serial so we can proceed to the next step.

Setting up a TCP/IP server

For this example we will create a TCP/IP nodejs server to be our network. This code can be found at

  1. const { Device, Network } = require("@tago-io/sdk"); const net = require("net"); const PORT = 3338; const network = new Network({ token: "" }); /* Your Network token here */ // Parse all data, this process can be on connector parser function parsePayload(payload) { const data = [ { variable: "serial", value: payload.readUInt32LE(1), }, { variable: "timestamp", value: payload.readUInt32LE(5), }, { variable: "external_supply_voltage", value: payload.readUInt8(9) + payload.readUInt8(10) * 0.01, }, { variable: "supply_voltage", value: payload.readUInt8(11) + payload.readUInt8(12) * 0.01, }, { variable: "battery_voltage", value: payload.readUInt8(13) + payload.readUInt8(14) * 0.01, }, { variable: "temperature", value: payload.readInt8(15) + payload.readUInt8(16) * 0.01, }, { variable: "gsm_level", value: payload.readInt8(17), }, ]; return data; } async function dataReceived(msg) { // parse data const data = parsePayload(msg);"data ", data); // get serial variable const serial = data.find((e) => e.variable == "serial").value.toString(); /** * Resolve the network token received by the device * The token dont need hyphen symbols as a divisor * In this method you can use a authentication token if needed */ const token = await network.resolveToken(serial); if (!token) { return console.log(`Token not found, serie: ${serial}`); } // send data to the device const device = new Device({ token }); device.sendData(data).then(console.log, console.log); } // Input example: 6d3930000088dd5a5c0b5e075c013d190300410120f14742ae4749414300 const server = net .createServer((socket) => { socket.on("data", dataReceived); }) .on("error", (err) => { throw err; }); server.listen(PORT);"Started Server at PORT", PORT);

That is it! Now you have a Network for your connectors and devices.