MicroPython on DIN rail

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
cmisztur
Posts: 3
Joined: Wed Sep 26, 2018 2:04 am

Re: MicroPython on DIN rail

Post by cmisztur » Mon Sep 13, 2021 4:10 am

slv.news wrote:
Tue Apr 07, 2020 9:45 am
Helllo

Just idea. I was one of funders of Controllino on Kickstarter
https://www.kickstarter.com/projects/24 ... compatible

I move to Micropython. I hope it's time to support something like this with MicroPython. It could be great for automation and industry.
Someone will make it ? :) I'll support as a first backer :)
Micropython inside DIN enclose with protection, relays, RS, CAN, WiFi/Eth ?

Best
Sylwester
Something like this?

Image

## Pycom Firmware

### OPERATION

#### BOOT
* blue => yellow => green
* wifi ok, ntp ok, mqtt ok
* blue => orange => green
* wifi ok, ntp nok, mqtt ok
* blue => yellow/orange => red => reset
* wifi ok, ntp ok/nok, i2c/mqtt nok
* blue => pink => reset
* wifi nok

#### RUNNING
* green => pink
* wifi nok
* green => pink => green
* wifi recovery
* green => pink (2s) => green => pink (3s) => ...
* mqtt recovery

### MQTT Interface

* base event topic: `l99/{grp}/{id}/evt/`
* base command topic: `l99/{grp}/{id}/cmd/`
* device subscribes to `l99/{grp}/{id}/cmd/+` and `l99/{grp}/all/cmd/+`
* device publishes on `l99/{grp}/{id}/evt/+`
* `broker.auth_key` requires that commands have matching authentication key in topic `l99/{grp}/{id}/cmd/{cmd}?auth=xyz`
* event payload are injected with timestamp epoch (time since boot or time since 1970 if RTC is synced)
* dict payloads injected with key-value `"_ts": 1570417312`
* list payloads injected with dictionary `{ "_ts": 1570417312 }`

* on MQTT disconnect (lwt) - retained
* topic: `l99/{grp}/30aea4787180/evt/status`
* evt payload: `{"connection": "offline", "id": "30aea4787180"}`

* on MQTT connect - retained
* topic: `l99/{grp}/30aea4787180/evt/` status
* evt payload: `{"connection": "online", "id": "30aea4787180"}`

* on digital input (DI0 - DI7), digital output (DO0 - DO7), analog input change (AI0 - AI7)
* I/O vaules are published on change
* topic: `l99/{grp}/{id}/evt/update`
* evt payload: `{"AI0": 6025, "DI5": 1, "DO7": 0}`

#### PING

* command: ping
* purpose: controller check
* cmd topic: `l99/{grp}/{id}/cmd/ping`, `l99/{grp}/all/cmd/ping`
* cmd payload: `{}`
* evt topic `l99/{grp}/{id}/evt/pong`

#### WRITE I/O

* command: write
* purpose: control digital outputs (DO0 - DO7), values 0 (off) / 1 (on)
* response published to `l99/{grp}/{id}/evt/update` if output state has changed
* cmd topic: `l99/{grp}/{id}/cmd/write`, `l99/{grp}/all/cmd/write`
* cmd payload:
```
[
{ "p": "DO0", "v": 0 },
{ "p": "DO1", "v": 0 },
{ "p": "DO2", "v": 0 },
{ "p": "DO3", "v": 0 },
{ "p": "DO4", "v": 0 },
{ "p": "DO5", "v": 0 },
{ "p": "DO6", "v": 0 },
{ "p": "DO7", "v": 0 }
]
```

#### READ I/O

* command: read
* purpose: on-demand read values from digital inputs (DI0 - DI7), digital outputs (DO0 - D07), analog inputs (AI0 - AI7)
* cmd topic: `l99/{grp}/{id}/cmd/read`, `l99/{grp}/all/cmd/read`
* cmd payload: `[ "DI1", "DO2", "AI1" ]`
* evt topic: `l99/{grp}/{id}/evt/read`
* evt payload: `[{"v": 0, "p": "DI1"}, {"v": 0, "p": "DO2"}, {"v": -16, "p": "AI1"}]`

#### I/O HEALTH

* command: health
* purpose: I/O health
* topic: `l99/{grp}/{id}/cmd/health`, `l99/{grp}/all/cmd/health`
* cmd payload: `{}`

#### RESET

* command: reset
* purpose: hardware reset device
* topic: `l99/{grp}/{id}/cmd/reset`, `l99/{grp}/all/cmd/reset`
* cmd payload: `{}`

#### CONFIG

* command: config
* purpose: change or retrieve running config
* evt topic: `l99/{grp}/{id}/evt/config`
* cmd topic: `l99/{grp}/{id}/cmd/config`, `l99/{grp}/all/cmd/config`

* cmd payload: `{}` or

```
{
"main_py": 'main.py',
"dupterm": True,
"boot_delay_ms": 1000,
"severity": 'D',
"sweep_ms": 100,
"wdt_ms": 2000,
"diag_ms": 60000,
"broker.auth_key": "xyz",
"broker.group_id": "g1",
"broker.client_id": "c1",
"broker.ip": '192.168.2.232',
"broker.port": 1883
"wlan.ssid": 'Roxy',
"wlan.pwd": 'pass',
"wlan.antenna": 0,
"wlan.timeout": 10000,
"wlan.security": 3
"ntp.ip1": 'pool.ntp.org',
"ntp.ip2": 'ntp.ubuntu.com',
"wlan.sync": 600
}
```

#### LOG

* command: log
* purpose: retrieve log file
* cmd topic: `l99/{grp}/{id}/cmd/log`, `l99/{grp}/all/cmd/log`
* cmd payload: `{ "clear": false }`
* evt topic `l99/{grp}/{id}/evt/log`
* evt payload: log file contents

#### EVALUATE

* command: evaluate
* purpose: execute arbitrary script
* cmd topic: `l99/{grp}/{id}/cmd/evaluate`, `l99/{grp}/all/cmd/evaluate`
* cmd payload:

```
{ "script": "import machine
a= machine.freq()
b= machine.freq()
ret_val = a+b"
}
```

* evt topic `l99/{grp}/{id}/evt/evaluate`
* evt payload: error or script result

#### INFO

* command: info
* purpose: retrieve hardware info
* cmd topic: `l99/{grp}/{id}/cmd/info`, `l99/{grp}/all/cmd/info`
* cmd payload: `{}`
* evt topic `l99/{grp}/{id}/evt/info`
* evt payload:

```
{
"device": {
"mem_free": 493200,
"id": "30aea4787180",
"release": "1.18.2.r7"
},
"boot": {
"reason": 2,
"reason.5": 0,
"reason.4": 0,
"reason.3": 0,
"reason.2": 113,
"reason.1": 0,
"reason.0": 0
},
"time": {
"uptime_ms": 311120544,
"rtc_sync": true,
"epoch_s": 1570417312
},
"wlan": {
"ip": "192.168.2.139",
"rssi": 0,
"ssid": "Roxy"
}
}
```

Post Reply