Serial
The Serial component configures a hardware serial port and its operating mode. It is available on devices with serial hardware, such as The Pill.
The Serial component uses Serial as RPC namespace and implements the following methods:
Serial.GetConfigto obtain the component's configurationSerial.SetConfigto update the component's configuration
Modes of Operation
The mode parameter in the configuration determines how the serial port is used. The set of supported modes depends on the device and is listed in the modes attribute.
mode | Description |
|---|---|
disabled | Serial port is inactive. If the Serial instance shares hardware with a port used for debug output, that function is also suspended. |
jsuart | Exposes the port to scripts via the UART API. Only one script can use the port at a time. |
mb_server | Operates as a Modbus RTU Server. Only available on devices with Modbus support. |
mb_client | Operates as a Modbus RTU Client. Creates an MbRtuClient component instance with the same id as the Serial instance, exposing raw register and coil read/write RPC methods. |
Methods
Serial.GetConfig
Retrieves the currently-applied configuration.
Parameters:
| Property | Type | Description |
|---|---|---|
| number | Id of the Serial component instance |
Serial.SetConfig
Updates the configuration of the Serial component. Configuration changes are applied at runtime without requiring a device restart.
Parameters:
| Property | Type | Description |
|---|---|---|
| number | Id of the Serial component instance |
| object | Configuration to apply |
Return:
| Property | Type | Description |
|---|---|---|
| bool | Whether a reboot is required for the new config to apply |
Attributes
The Serial component exports the following attribute:
| Property | Type | Description |
|---|---|---|
| array of strings | Set of modes that this Serial instance supports. |
Configuration
| Property | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| number | Id of the Serial component instance | |||||||||||||||
| string | Operating mode for the serial port. Supported modes are listed in the | |||||||||||||||
| object | Serial port parameters, used as applicable for the selected mode.
| |||||||||||||||
| object | Modbus RTU Server configuration
| |||||||||||||||
| object | Modbus RTU Client configuration. Reserved for future use. |
The serial.format config parameter accepts a 3-char string, where each of the chars configures some aspect of the serial framing:
- Number of data bits,
7or8 - Parity,
N,EorOfor None, Even and Odd respectively - Number of stop bits,
1,2or the letterxfor 1.5
Examples
Serial.GetConfig example
- Serial.GetConfig HTTP GET Request
- Serial.GetConfig Curl Request
- Serial.GetConfig Mos Request
http://192.168.33.1/rpc/Serial.GetConfig?id=0
curl -X POST -d '{"id":1,"method":"Serial.GetConfig","params":{"id":0}}' http://${SHELLY}/rpc
mos --port ${PORT} call Serial.GetConfig '{"id":0}'
Response
- Serial.GetConfig HTTP GET Response
- Serial.GetConfig Curl Response
- Serial.GetConfig Mos Response
{
"mode": "disabled",
"serial": {
"baud": 115200,
"format": "8N1",
"hd": false,
"de_al": false
},
"mb_server": {
"addr": 42
}
}
{
"id": 1,
"params": {
"mode": "disabled",
"serial": {
"baud": 115200,
"format": "8N1",
"hd": false,
"de_al": false
},
"mb_server": {
"addr": 42
}
}
}
{
"mode": "disabled",
"serial": {
"baud": 115200,
"format": "8N1",
"hd": false,
"de_al": false
},
"mb_server": {
"addr": 42
}
}
Serial.SetConfig example
- Serial.SetConfig HTTP GET Request
- Serial.SetConfig Curl Request
- Serial.SetConfig Mos Request
http://192.168.33.1/rpc/Serial.SetConfig?id=0&config={"mode":"jsuart","serial":{"baud":9600,"format":"8E1"}}
curl -X POST -d '{"id":1,"method":"Serial.SetConfig","params":{"id":0,"config":{"mode":"jsuart","serial":{"baud":9600,"format":"8E1"}}}}' http://${SHELLY}/rpc
mos --port ${PORT} call Serial.SetConfig '{"id":0,"config":{"mode":"jsuart","serial":{"baud":9600,"format":"8E1"}}}'
Response
- Serial.SetConfig HTTP GET Response
- Serial.SetConfig Curl Response
- Serial.SetConfig Mos Response
{
"restart_required": false
}
{
"id": 1,
"params": {
"restart_required": false
}
}
{
"restart_required": false
}