Skip to content

Commit

Permalink
Feature/auto fbname detection (#6)
Browse files Browse the repository at this point in the history
* auto determining FB name for MQTT pub and sup topics, updating docs
  • Loading branch information
MichielVanwelsenaere authored Jul 15, 2019
1 parent 5e2a3ef commit 490f463
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 78 deletions.
9 changes: 5 additions & 4 deletions docs/FunctionBlocks/FB_INPUT_BINARYSENSOR_MQTT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ OUTPUT(S)
- EVENT_F: output high for one clock cycle when a falling edge is detected on debounced input `BS`.

METHOD(S)
- InitMQTT: enables MQTT events on the FB: sets the topic to publish to and sets the pointer to the `MQTTPublishQueue`.
- InitMQTT: enables MQTT events on the FB: sets the MQTT publish topic and sets the pointer to the `MQTTPublishQueue`.

### __MQTT Event Behaviour__
Requires method call `InitMQTT` to enable MQTT capabilities.
Expand All @@ -27,7 +27,7 @@ Requires method call `InitMQTT` to enable MQTT capabilities.
| **Rising edge** | A signal change from low to high is detected on input `BS`. | `ON` | 2 | `TRUE` | no
| **Falling edge** | A signal change from high to low is detected on input `BS`. | `OFF` | 2 | `TRUE` | no


MQTT publish topic is a concatenation of the publish prefix variable and the function block name.

### __Code example__

Expand All @@ -40,10 +40,11 @@ FB_DI_BS_001 :FB_INPUT_BINARYSENSOR_MQTT;
- Init MQTT method call (called once during startup):
```
FB_INPUT_BINARYSENSOR_MQTT.InitMQTT(MQTTPublishPrefix:= ADR(MQTTBinarySensorPrefix), (* pointer to string prefix for the MQTT publish topic *)
MQTTTopicSuffix := 'FB_DI_BS_001', (* value to suffix the the MQTT topic, should be unique for each FB *)
pMQTTPublishQueue := ADR(MQTTVariables.fbMQTTPublishQueue) (* pointer to MQTTPublishQueue to send a new MQTT event *)
pMQTTPublishQueue := ADR(MQTTVariables.fbMQTTPublishQueue) (* pointer to MQTTPublishQueue to send a new MQTT event *)
);
```
The MQTT publish topic in this code example will be `WAGO-PFC200/Out/DigitalInputs/BinarySensors/FB_DI_BS_001` (MQTTBinarySensorPrefix variable + function block name).


- reading digital input for events (cyclic):
```
Expand Down
6 changes: 4 additions & 2 deletions docs/FunctionBlocks/FB_INPUT_PUSHBUTTON_MQTT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ OUTPUT(S)
- LONG: output high for one clock cycle when a long push is detected on input `PB`.

METHOD(S)
- InitMQTT: enables MQTT events on the FB. Sets the topic to publish to and sets the pointer to the `MQTTPublishQueue`.
- InitMQTT: enables MQTT events on the FB: sets the MQTT publish topic and sets the pointer to the `MQTTPublishQueue`.

### __MQTT Event Behaviour__
Requires method call `InitMQTT` to enable MQTT capabilities.
Expand All @@ -27,6 +27,8 @@ Requires method call `InitMQTT` to enable MQTT capabilities.
| **Pushbutton double press** | A double pushbutton press is detected on input `PB`. | `DOUBLE` | 2 | `FALSE` | no
| **Pushbutton long press** | A long pushbutton press is detected on input `PB`. | `LONG` | 2 | `FALSE` | no

MQTT publish topic is a concatenation of the publish prefix variable and the function block name.

### __Code example__

- variables initiation:
Expand All @@ -38,10 +40,10 @@ FB_DI_PB_001 :FB_INPUT_PUSHBUTTON_MQTT;
- Init MQTT method call (called once during startup):
```
FB_DI_PB_001.InitMQTT(MQTTPublishPrefix:= ADR(MQTTPushbuttonPrefix), (* pointer to string prefix for the MQTT publish topic *)
MQTTTopicSuffix := 'FB_DI_PB_001', (* value to suffix the the MQTT topic, should be unique for each FB *)
pMQTTPublishQueue := ADR(MQTTVariables.fbMQTTPublishQueue) (* pointer to MQTTPublishQueue to send a new MQTT event *)
);
```
The MQTT publish topic in this code example will be `WAGO-PFC200/Out/DigitalInputs/Pushbuttons/FB_DI_PB_001` (MQTTPushbuttonPrefix variable + function block name).

- reading digital input for events (cyclic):
```
Expand Down
8 changes: 7 additions & 1 deletion docs/FunctionBlocks/FB_OUTPUT_SWITCH_MQTT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ OUTPUT(S)
- OUT: output to switch digital output on and off. Can be connected to a relay for example.

METHOD(S)
- InitMQTT: enables MQTT events on the FB: sets the topic to publish to, sets the topic to subscribe to, registers to the callbackcollector and sets the pointer to the `MQTTPublishQueue`.
- InitMQTT: enables MQTT events on the FB: sets the MQTT publish topic & subscribe topic, registers to the callbackcollector and sets the pointer to the `MQTTPublishQueue`.
- PublishRecived: callback method called by the callbackcollector when a message is received on the subscribed topic by the callbackcollector.

### __MQTT Event Behaviour__
Expand All @@ -27,6 +27,8 @@ Requires method call `InitMQTT` to enable MQTT capabilities.
| **Output changes to high** | The digtal output changes state to high. | `TRUE` | 2 | `FALSE` | yes
| **Output changes to low** | The digtal output changes state to low. | `FALSE` | 2 | `FALSE` | yes

MQTT publish topic is a concatination of the publish prefix and the function block name.

### __MQTT Subscription Behaviour__
Requires method call `InitMQTT` to enable MQTT capabilities.
Commands are executed by the FB if the topic `MQTTSubscribeTopic` matches the MQTT topic and the payload exists in the table below.
Expand All @@ -36,6 +38,8 @@ Commands are executed by the FB if the topic `MQTTSubscribeTopic` matches the MQ
| **Change output to high** | Request to change output to high. | `TRUE` | Command executed when `PRIOHIGH` and `PRIOLOW` inputs are low.
| **Change output to low** | Request to change output to low. | `FALSE` | Command executed when `PRIOHIGH` and `PRIOLOW` inputs are low.

MQTT subscription topic is a concatenation of the subscribe prefix variable and the function block name.

### __Code example__

- variables initiation:
Expand All @@ -54,6 +58,8 @@ FB_DO_SW_001.InitMQTT(MQTTPublishPrefix:= ADR(MQTTPubSwitchPrefix),
pMQTTCallbackCollector := ADR(MQTTVariables.collector_FB_OUTPUT_SWITCH_MQTT) (* pointer to CallbackCollector to receive MQTT subscription events *)
);
```
The MQTT publish topic in this code example will be `WAGO-PFC200/Out/DigitalOutputs/FB_DO_SW_001` (MQTTPubSwitchPrefix variable + function block name). The subscription topic will be `WAGO-PFC200/In/DigitalOutputs/FB_DO_SW_001` (MQTTSubSwitchPrefix variable + function block name).


- checking for events to switch the digital output (cyclic):
```
Expand Down
Binary file modified src/HomeAutomation.project
Binary file not shown.
Loading

0 comments on commit 490f463

Please sign in to comment.