This page covers two small APIs:
usb module of the supervision peer, which lists the USB devices and built-in serial ports detected by the gateway. Use it to find the port of a KNX, EnOcean, Z-Wave or Modbus USB interface before you create a gateway;modem peer, which reports the state of the LTE modem (link, SIM, signal, operator, data usage, SMS) on gateways that have one.
peer('supervision').require('usb', function(err, usb){
usb.getDevices(function(err, devices){
devices.forEach(function(d){ console.log(d.product, d.tty || d.port) })
})
})
Over HTTP: GET /peers/supervision/usb/getDevices (see REST: peers dispatcher).
getDevices(callback)Returns an array of devices. USB devices come first, then the built-in serial ports of the gateway, listed as pseudo-devices with vendor: "Weble" and a product such as RS485 1, RS485 2 or KNX TP UART. Built-in ports depend on the hardware model and are listed even when nothing is connected.
If USB support is disabled on the gateway, the callback receives the error usb deactivated. During startup, the answer waits for the first USB scan.
| Field | Meaning |
|---|---|
port |
USB location, renamed on some models to a readable label (USB 1…); the original value is kept in hardwarePort. For a built-in serial port, port is the serial device itself (/dev/ttyS1, /dev/ttymxc0…). |
tty |
Array of serial ports opened by a USB device, for example ["/dev/ttyACM0"] or ["/dev/ttyUSB0"] (COM16 on Windows). This is the value to enter as the port of a serial gateway. |
product, productId |
Product name and id. |
vendor, vendorId, manufacturer |
Vendor. |
serial |
Serial number. |
sd |
Storage devices only: partitions and file system, for example [["sda1","vfat"]]. Partitions are mounted under /media/<partition>. |
driver, class, bus, number, filepath |
Kernel driver, USB class and position on the bus. |
mac, iface |
USB network adapters: MAC address and network interface. |
Fields without a value are omitted.
// Example answer
[
{ port: "USB 1.2", product: "KNX-USB Interface", vendor: "...", tty: ["/dev/ttyACM0"] },
{ port: "/dev/ttyS1", product: "RS485 1", vendor: "Weble", manufacturer: "Weble" }
]
The list is refreshed when a device is plugged in or removed, and every 10 minutes. The module emits devices with the full array after each change:
usb.on('devices', function(devices){ console.log(devices.length, 'devices') })
getDevices and find the device by product or vendor.tty[0] (or port for a built-in port) as the serial port of the gateway.A device that is missing from the list is not seen by the operating system (cable, power, USB hub): configuring a gateway on it will not help.
system.getSerialPortsgetSerialPorts of the system module lists the serial ports known to the operating system, without USB information. Use it to cross-check when a USB device has an empty tty.
The modem runs in its own process: it is a separate peer called modem, with a single module api. It exists only on gateways with an LTE modem. The modem is switched on and off with setModemEnable of the system module; its APN, PIN and mode are in the gsm section of the network configuration.
peer('modem').require('api', function(err, modem){
modem.getInfo(function(err, info){
console.log('internet:', info.internet, 'SIM:', info.simState, 'signal:', info.signal)
})
})
When the modem is absent or still starting, methods answer Modem not connected or Modem not ready.
| Method | Returns |
|---|---|
getInfo(callback) |
Current state: internet (connection up), internetStatus, linked (registered on the network), simState (READY when the SIM is unlocked), signal, cop (operator), data (data counters), model, imei, iccid, pending (true while the expected connection is not up yet). Fields appear once the modem has reported them. |
getCOP(callback) |
Current mobile operator. |
getCOPSCache(callback) |
Operators found by the last scan (cached, no new scan). |
getDataConsumption(callback) |
Data counters of the modem: { send, receive } in bytes. |
getMessages(callback) |
SMS stored in the modem. |
getCOPS(true, callback)scans the available operators and stops the internet connection during the scan, then restarts it. On a gateway connected only through LTE, the gateway, its VPN and your API connection are cut for the duration of the scan. While the scan runs, the callback is called every 5 seconds with'progress'before the final result. PrefergetCOPSCache.
| Method | Effect |
|---|---|
setCOP(operator, callback) |
Selects the mobile operator. |
changePreferedNetwork(mode, callback) |
Changes the preferred network type: auto, 3G or 2G; any other value selects 4G/3G. |
sendMessage({ receiver, text }, callback) |
Sends an SMS. |
deleteMessages(ids, callback) / clearMessages(callback) |
Deletes some or all SMS stored in the modem. |
restart() |
Restarts the modem service. |
sendMessagesends a real SMS, billed on the SIM subscription. Test with your own number, and never call it in a loop.
Listen on the module object: change (new state, same shape as getInfo), internet connected, internet disconnected, modem linked, modem unlinked.
| Symptom | Cause and fix |
|---|---|
usb deactivated |
USB support is disabled on this gateway. |
| The USB interface is not listed | Not detected by the operating system: check the cable, the power supply, try another USB port. |
tty is empty |
The device has no serial driver loaded. Cross-check with system.getSerialPorts. |
Modem not connected / Modem not ready |
No modem, modem disabled, or still starting. Check setModemEnable and wait a minute. |
| The gateway went offline for a while | A getCOPS(true) scan was running on an LTE-only gateway. |
getSerialPorts, setModemEnable.gsm section (APN, PIN).