Skip to content

Establishing Host Connection and Power

ModuSio devices can be connected to the Network via Ethernet or Wifi. Please select the tab for your preferred option:

Ethernet: Network and Power Connection

When the MIO04 is connected to the host via Ethernet, the power should be provided via Power-Over-Ethernet.

ModuSio devices are Class 2 (3,84–6,49 W) PoE powered devices. Connect the ModuSio Device to a PoE source that can supply class 2 devices. ModuSios expect the PoE power as phantom power, i.e. using the Ethernet Tx and Rx pins.

PoE connection

The green LED on the MIO04 is turned on to indicate power is ok and firmware is up and running.

Initial Device Configuration

For initial configuration, connect the SERVICE interface to a computer via USB cable and start a terminal program. See Instructions for details.

Press Enter in the Terminal program, and you should see the config prompt:

config>

Configure Device ID

To identify the device in the network, configure a device ID. This ID is used as the network hostname and as a prefix to identify the services provided by the device.

Each device in the network shall have a unique name. The name shall consist only of alphanumeric characters, - and _. Avoid blanks and special characters.

config> param device-id MIO04-1
Setting device-id to 'MIO04-1'
A 'reboot' is required to activate the new setting!

Select Ethernet as Host Interface

Configure the device for Ethernet operation. The device is configured for Ethernet when it is NOT configured for Wifi. So we clear Wifi settings:

config> param wifi-ssid ""
Delete wifi-ssid

Info

You can ignore the message: Can't set wifi-ssid: ESP_ERR_NVS_NOT_FOUND. This is normal if wifi has not been configured before.

Configure IP Address

The ModuSio needs an IP address in the network. It can be configured to use a static IP address or to use dynamic IP address, provided by a DHCP server.

Setup for DHCP

To obtain the devices IP address from a DHCP server, clear any static IP address setting:

config> param static-ip ""
Delete static-ip

Info

You can ignore the message: Can't set static-ip: ESP_ERR_NVS_NOT_FOUND. This is normal if no static IP has not been configured before.

Activate the changes:

config> reboot

Setup Static IP

To use a static IP address, configure the IP-Address, Gateway and Network Mask using the static-ip command. The three parameters have to be specified as a single string, separated by colons (:), <ip>:<netmask>:<gateway>.

config> param static-ip 192.168.1.56:255.255.255.0:192.168.1.1
Setting static-ip to '192.168.1.56:255.255.255.0:192.168.1.1'
A 'reboot' is required to activate the new setting!
Activate the changes:
config> reboot

Connection Test

Now try to test the connection using ping from a computer in the same network as your device. Use the device ID of your device and append .local.

$ ping MIO04-1.local
PING MIO04-1.local (192.168.1.56) 56(84) bytes of data.
64 bytes from 192.168.1.56: icmp_seq=1 ttl=255 time=57.1 ms
64 bytes from 192.168.1.56: icmp_seq=2 ttl=255 time=76.4 ms

Wifi: Network and Power Connection

When using Wifi, supply the ModuSio by a power supply, capable of delivering 12V..24VDC, 5W. Use contacts 5+6 and 7+8 to supply the power. Polarity doesn't matter.

Wifi connection

The green LED on the MIO04 is turned on to indicate power is ok and firmware is up and running.

Initial Device Configuration

For initial configuration, connect the SERVICE interface to a computer via USB cable and start a terminal program. See Instructions for details.

Press Enter in the Terminal program, and you should see the config prompt:

config>

Configure Device ID

To identify the device in the network, configure a device ID. This ID is used as the network hostname and as a prefix to identify the services provided by the device.

Each device in the network shall have a unique name. The name shall consist only of alphanumeric characters, - and _. Avoid blanks and special characters.

config> param device-id MIO04-1
Setting device-id to 'MIO04-1'
A 'reboot' is required to activate the new setting!

Select Wifi as Host Interface

Configure the device for Wifi operation. You need the Access Point's Name (SSID) and a password.

config> param wifi-ssid <my-access-point-name>
config> param wifi-pw <my-secret-password>

Warning

It is not possible to connect to Access Points that don't require a password.

Configure IP Address

The ModuSio needs an IP address in the network. It can be configured to use a static IP address or to use dynamic IP address, provided by a DHCP server.

Setup for DHCP

To obtain the devices IP address from a DHCP server, clear any static IP address setting:

config> param static-ip ""
Delete static-ip

Info

You can ignore the message: Can't set static-ip: ESP_ERR_NVS_NOT_FOUND. This is normal if no static IP has not been configured before.

Activate the changes:

config> reboot

Setup Static IP

To use a static IP address, configure the IP-Address, Gateway and Network Mask using the static-ip command. The three parameters have to be specified as a single string, separated by colons (:), <ip>:<netmask>:<gateway>.

config> param static-ip 192.168.1.56:255.255.255.0:192.168.1.1
Setting static-ip to '192.168.1.56:255.255.255.0:192.168.1.1'
A 'reboot' is required to activate the new setting!
Activate the changes:
config> reboot

Connection Test

Now try to test the connection using ping from a computer in the same network as your device. Use the device ID of your device and append .local.

$ ping MIO04-1.local
PING MIO04-1.local (192.168.1.56) 56(84) bytes of data.
64 bytes from 192.168.1.56: icmp_seq=1 ttl=255 time=57.1 ms
64 bytes from 192.168.1.56: icmp_seq=2 ttl=255 time=76.4 ms

Troubleshooting Wifi Connection

In case Wifi connection doesn't work, enter reboot in the SERVICE console and check the log messages.

Look for messages beginning with wifi: and io4edge_net:. In case of success, you see something like

...
I (848) wifi:connected with my-access-point-name, aid = 1, channel 6, BW20, bssid = ...
...
I (2573) io4edge_net: Got IP Address
I (2573) io4edge_net: ~~~~~~~~~~~
I (2573) io4edge_net: ETHIP:192.168.1.56
I (2574) io4edge_net: ETHMASK:255.255.255.0
I (2574) io4edge_net: ETHGW:192.168.1.1
I (2574) io4edge_net: ~~~~~~~~~~~
...

If connection establishment isn't successful, you see periodically something like this:

I (6954) io4edge_wifi: Disconnected, reconnect

You can also scan for available access points. To enable wifi scanning, just set a dummy access point name:

config> param wifi-ssid foo
config> reboot
...
config> param wifi-scan
Total APs scanned = 2
                                    SSID RSSI Channel
                                  slinky -47   6
                            OfficeRouter -53   1

Serial Interfaces Demo with REST API

In this demo, we demonstrate how to use a COM port of the MIO04 with the REST API firmware variant. We use a simple Python script to send and receive data via the REST API.

For this demo, we create a hardware loop between the RS232 transmit and receive pins of the COM1 RS232 interface. We connect pin 2 and pin 3 of the COM port D-sub connector:

COM loop

We use the default parameter configuration of the COM port, which is 9600 baud, 8 data bits, no parity, 1 stop bit.

Demo Software

The following Python script periodically writes messages to the COM port and prints any received messages to the console.

Please adjust the URL according to the IP address of the MIO04 on your network.

All other settings can remain unchanged if the MIO04 is configured with the factory default settings.

If you have changed the username or password, please adjust the USERNAME and PASSWORD variables accordingly.

If you have loaded your own TLS certificate on the MIO04, please adjust the TRUST_CERT variable to point to your certificate file. If you want to disable TLS certificate verification, set INSECURE to True.

#!/usr/bin/env python3

import asyncio
import base64
import contextlib
import ssl
from typing import Dict, Optional

from websockets.asyncio.client import ClientConnection
from websockets.asyncio.client import connect as ws_connect


URL = 'wss://192.168.24.213:443/api/v1/com1/ws'
USERNAME = 'io4edge'
PASSWORD = 'core_io4edge'

SEND_INTERVAL_SECONDS = 1.0
MESSAGE = 'hello world'

INSECURE = True
CAFILE: Optional[str] = None
TRUST_CERT: Optional[str] = None


def build_ssl_context() -> ssl.SSLContext:
    ctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)

    if TRUST_CERT:
        ctx.load_verify_locations(cafile=TRUST_CERT)
    elif CAFILE:
        ctx.load_verify_locations(cafile=CAFILE)

    if INSECURE:
        ctx.check_hostname = False
        ctx.verify_mode = ssl.CERT_NONE

    return ctx


def build_basic_auth_headers() -> Dict[str, str]:
    token = base64.b64encode(f'{USERNAME}:{PASSWORD}'.encode('utf-8')).decode('ascii')
    return {'Authorization': f'Basic {token}'}


async def recv_loop(ws: ClientConnection) -> None:
    async for msg in ws:
        print(f'recv: {msg}')


async def main_loop() -> None:
    async with ws_connect(
        URL,
        ssl=build_ssl_context(),
        additional_headers=build_basic_auth_headers(),
        compression=None,
        max_size=None,
    ) as ws:
        print(f'connected: {URL}')
        recv_task = asyncio.create_task(recv_loop(ws))

        try:
            while True:
                await ws.send(MESSAGE)
                print(f'sent: {MESSAGE}')
                await asyncio.sleep(SEND_INTERVAL_SECONDS)
        finally:
            recv_task.cancel()
            with contextlib.suppress(asyncio.CancelledError):
                await recv_task


def main() -> int:
    try:
        asyncio.run(main_loop())
    except KeyboardInterrupt:
        print('stopped')
    return 0


if __name__ == '__main__':
    raise SystemExit(main())

Now run the script and you should see messages being sent and received every second:

$ python quickstart.py
connected: wss://192.168.24.213:443/api/v1/com1/ws
sent: hello world
recv: b'hello world'
sent: hello world
recv: b'hello world'
sent: hello world
recv: b'hello world'