This project primarily for my bachelor thesis. This is implementation of protocol IEC-104 for Unipi Patron series devices.
Python >= 3.9
aiomqtt==2.1.0
asyncio==3.4.3
requests==2.31.0- Update and upgrade your package repository.
sudo apt update && sudo apt upgrade- Install python3.
sudo apt install python3- Install pip package manager.
sudo apt install python3-pip -y- Create virtual enviroment for your project.
python3 -m venv venv
source venv/bin/activate- Use the package manager pip.
pip install -r requirements.txtIn config_parameters.json setup your IP address and MQTT configuration.
{
"server": {
"ip_address": "192.168.1.10",
"port": 2404,
"k": 12,
"w": 8,
"t0": 30,
"t1": 15,
"t2": 10,
"t3": 20
},
"mqtt": {
"enabled": true,
"mqtt_broker_ip": "192.168.1.10",
"mqtt_broker_port": 1883,
"mqtt_username": "mqtt",
"mqtt_password": "MQTTpass123",
"mqtt_qos": 1
}
}In mapping_io.json setup your IOA address to correct pin.
{ "evok_conf": [
{
"host": "192.168.1.10",
"port": 8080,
"ASDU_address": 1
}
],
"mappings": [
{
"ioa": 1,
"pin": "ai",
"pin_id": "2_02",
"command_method": "evok_api"
},
{
"ioa": 2,
"pin": "do",
"pin_id": "1_01",
"command_method": "evok_api"
},
{
"ioa": 3,
"pin": "ao",
"pin_id": "1_01",
"command_method": "gpio"
},
{
"ioa": 4,
"pin": "di",
"pin_id": "1_01",
"command_method": "gpio"
},
{
"pin": "ai",
"pin_id": "2_02",
"command_method": "evok_api"
},
{
"ioa": 2,
"pin": "do",
"pin_id": "1_01",
"command_method": "evok_api"
},
{
"ioa": 3,
"pin": "ao",
"pin_id": "1_01",
"command_method": "gpio"
},
{
"ioa": 4,
"pin": "di",
"pin_id": "1_01",
"command_method": "gpio"
}
]
}In bachelor project run server on RTU with:
python3 main_server.pyIn bachelor project run client on MTU with:
python3 main_client_app.pyFor use only IEC-104 communication, start server and register callbacks.
import asyncio
from server import ServerIEC104
def on_connect(host, port, rc):
pass
async def on_message(session, apdu, data, cb_on_sent):
pass
def on_disconnect(session):
pass
async def main(server):
my_server = ServerIEC104()
my_server.register_callback_on_connect = on_connect
my_server.register_callback_on_message = on_message
my_server.register_callback_on_disconnect = on_disconnect
task_server = asyncio.create_task(my_server.start())
# your code ...
await task_server
if __name__ == "__main__":
asyncio.run(main())Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.