Skip to content

Commit fd2d25b

Browse files
authored
Add ability to specify repeats for raw Pilight strings (#803)
* Add ability to specify repeats for raw Pilight strings * Updated RF Pilight doc to add raw transmission tut Added information about transmitting raw messages using the MQTTtoPilight topic, including using the new repeats functionality. Fixed some scattered English mistakes.
1 parent 5890bf7 commit fd2d25b

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.pio
22
.vscode
33
*_env.ini
4+
**/.DS_Store

docs/use/rf.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,31 @@ Generate your RF signals by pressing a remote button or other and you will see :
7373

7474
![](../img/OpenMQTTGateway_Pilight_Digoo-DG-R8S.png)
7575

76-
### Send data by MQTT to convert it on RF signal
77-
**ON**
76+
### Send data by MQTT to transmit a RF signal
7877

78+
#### Using a known protocol
79+
**ON**
7980
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight" -m '{"message":"{\"systemcode\":12,\"unitcode\":22,\"on\":1}","protocol":"elro_400_switch"}'`
8081

8182
**OFF**
82-
8383
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight" -m '{"message":"{\"systemcode\":12,\"unitcode\":22,\"off\":1}","protocol":"elro_400_switch"}'`
8484

85-
Theses commands will send by RF the signals to actuate an elro_400 switch
85+
These commands will transmit by RF the signals to actuate an elro_400 switch.
86+
87+
#### Using a raw signal
88+
You can transmit raw signal data by using the "raw" protocol. This uses the Pilight pulse train string format. One such example string, representing a transmission for Nexus protocol weather stations, looks like this: `c:03020202010102020102010101010101010202020201020102020202020101010201010202;p:500,1000,2000,4000;r:12@`. This string represents pulses and gaps directly.
89+
90+
Each number in the list after `p:` that ends with `;` stands for **p**ulse and gap lengths in microseconds (µs). In this example, we have a list containing lengths of 500µs, 1000µs, 2000µs, and 4000µs.
91+
92+
Each number after `c:` and ended by `;` represents a **c**ode that references the `p:` list by index. In this example, the first 4 numbers after `c:` are 0, 3, 0, and 2, which reference `p:`[0] = 500, `p:`[3] = 4000, `p:`[0] = 500, and `p:`[2] = 2000, respectively. In the language of digital radio transceiving, the most basic unit is usually a pulse and gap pair; in other words, 0s and 1s are represented by a pulse followed by a gap (lack of pulse) and the time lengths of these pulses and gaps. Different protocols have different pulse lengths and gap lengths representing 0, and a different one representing 1. Because of this pulse-gap nature, the codes in `c:` must be taken as pairs; the first number in a pair represents the length of the pulse, and the second number the subsequent gap. In this example, the first pair, 03, represents a pulse of 500µs followed by a gap of 4000µs. The next pair, 02, represents a pulse of 500µs followed by a gap of 2000µs.
93+
94+
The number after `r:` represents how many times the message in the string is to be **r**epeated. The `r:` block is optional. The default number of repeats if `r:` is not specified is 10. Greater than about 100 repeats will cause a crash due to memory usage. If this example were written without specifying repeats, it would look like this: `{"raw":"c:03020202010102020102010101010101010202020201020102020202020101010201010202;p:500,1000,2000,4000@"}`
95+
96+
The entire string must end in a `@`. Each block must end in a `;`, but if it is the last block in the string, the `@` replaces the `;`. Since the `r:` block is optional, this last block could be either `p:` or `r:`.
97+
98+
The JSON for the MQTT message to `home/OpenMQTTGateway/commands/MQTTtoPilight` should specify the pulse train string as the value for the "raw" key: `{"raw":"c:03020202010102020102010101010101010202020201020102020202020101010201010202;p:500,1000,2000,4000;r:12@"}`.
99+
100+
e.g. `mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight" -m '{"raw":"c:03020202010102020102010101010101010202020201020102020202020101010201010202;p:500,1000,2000,4000;r:12@"}'`
86101

87102
## RF with SONOFF RF BRIDGE
88103
### Receiving data from RF signal

main/ZgatewayPilight.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,21 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
108108
const char* raw = Pilightdata["raw"];
109109
if (raw) {
110110
uint16_t codes[MAXPULSESTREAMLENGTH];
111-
int msgLength = rf.stringToPulseTrain(
112-
raw, codes, MAXPULSESTREAMLENGTH);
111+
int repeats = rf.stringToRepeats(raw);
112+
if (repeats < 0) {
113+
switch (repeats) {
114+
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_R:
115+
Log.trace(F("'r' not found in string, or has no data" CR));
116+
break;
117+
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_END:
118+
Log.trace(F("';' or '@' not found in data string" CR));
119+
break;
120+
}
121+
repeats = 10;
122+
}
123+
int msgLength = rf.stringToPulseTrain(raw, codes, MAXPULSESTREAMLENGTH);
113124
if (msgLength > 0) {
114-
rf.sendPulseTrain(codes, msgLength);
125+
rf.sendPulseTrain(codes, msgLength, repeats);
115126
Log.notice(F("MQTTtoPilight raw ok" CR));
116127
} else {
117128
Log.trace(F("MQTTtoPilight raw KO" CR));

main/config_RF.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ extern void MQTTtoPilight(char* topicOri, JsonObject& RFdata);
7878
#define subjectMQTTtoPilight "/commands/MQTTtoPilight"
7979
#define subjectPilighttoMQTT "/PilighttoMQTT"
8080
#define subjectGTWPilighttoMQTT "/PilighttoMQTT"
81-
#define PilightRAW "RAW"
8281
#define repeatPilightwMQTT false // do we repeat a received signal by using mqtt with Pilight gateway
8382

8483
/*-------------------CC1101 frequency----------------------*/

0 commit comments

Comments
 (0)