Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/latchdevel/picode
C/C++ library to manage OOK protocols supported "pilight" project
https://github.com/latchdevel/picode
315mhz 433mhz ask espilight ook picode pilight rc-switch weather-station
Last synced: about 1 month ago
JSON representation
C/C++ library to manage OOK protocols supported "pilight" project
- Host: GitHub
- URL: https://github.com/latchdevel/picode
- Owner: latchdevel
- License: lgpl-3.0
- Created: 2021-03-13T21:25:55.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-10-19T16:47:08.000Z (about 2 years ago)
- Last Synced: 2023-03-23T02:38:53.740Z (almost 2 years ago)
- Topics: 315mhz, 433mhz, ask, espilight, ook, picode, pilight, rc-switch, weather-station
- Language: C
- Homepage: https://manual.pilight.org/protocols/433.92/index.html
- Size: 303 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PiCode Library
C/C++ library to manage OOK protocols supported by [**"pilight"**](https://github.com/pilight/pilight) project.
Works on any libc/libc++ compatible system, like macOS, FreeBSD, Linux, even Windows.
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
[![Build tests](https://github.com/latchdevel/PiCode/actions/workflows/BuildTest.yml/badge.svg)](https://github.com/latchdevel/PiCode/actions/workflows/BuildTest.yml)A large number of wireless protocols of RC switches and weather stations using the 433/315Mhz radio frequency band via ASK/OOK pulse modulation are implemented by the excellent work of the "pilight" community. A list of supported protocols can be found in the pilight manual: https://manual.pilight.org/protocols/433.92/index.html
Inspired by [**"ESPiLight"**](https://github.com/puuu/ESPiLight) project, provides a standard C++ class to should help to implement IoT bridges between the RF 433/315MHz band and internet protocols.
The "pilight" project defines a special string format to easily transcribe an OOK pulse train, in order to be able to exchange it with other systems, such as a remote RF receiver/transmitter.
pilight string format: `c: ; p: , , ... [;r:] @`
pilight string example: `c:001010101100101010101010101010110010101102;p:700,1400,7650;r:5@`
The main features are to encode and decode the pilight strings.
When decoding a pilight string is successful, a json array is returned containing the protocol matches, as sometimes decoded string matches more than one protocol.pilight string: `c:010002000200020002000200020002000200020002000200020002000200020002000200020002020000020200020002000002000200020200000200020002000203;p:315,2835,1260,10710@`
decode as:
```json
{
"protocols": [
{
"arctech_contact": {
"id": 92,
"unit": 0,
"state": "opened"
}
},
{
"arctech_dimmer": {
"id": 92,
"unit": 0,
"state": "on"
}
},
{
"arctech_screen": {
"id": 92,
"unit": 0,
"state": "up"
}
},
{
"arctech_switch": {
"id": 92,
"unit": 0,
"state": "on"
}
},
{
"smartwares_switch": {
"id": 92,
"unit": 0,
"state": "on"
}
}
]
}
```To encode to pilight string, you must provide the protocol and custom parameters of that protocol in json format.
Example: `{"arctech_switch":{"id":92,"unit":0,"on":1}}`
## BUILD
No external depends, can run on any libc/libc++ compatible system, like macOS, FreeBSD, Linux, even Windows.
```
$ git clone https://github.com/latchdevel/PiCode (or download .zip)
$ cd PiCode
$ mkdir build
$ cd build
$ cmake .. (or "cmake -DCMAKE_BUILD_TYPE=debug .." for debug)
$ make
$ make install (optional)
# make picode_example (optional C++ example)
# make cpicode_example (optional C example)
$ make uninstall (to uninstall)
```## C example
```c
/*
Example of using the pure C PiCode Library
https://github.com/latchdevel/PiCodeCopyright (c) 2021 Jorge Rivera. All right reserved.
License GNU Lesser General Public License v3.0.*/
#include /* printf() */
#include /* free(), uint8_t */#include "src/cPiCode.h" /* Pure C PiCode library */
int main(){
int result = 0;
printf("cpicode_example (%s)\n", STRINGIFY(BUILD_VERSION));
printf("Compiled at " __DATE__ " " __TIME__ " %s (%s)\n",STRINGIFY(BUILD_COMPILER), BUILD_TYPE );/* Get PiCode library version */
char* library_version = getPiCodeVersion();
if (library_version){
printf("PiCode library version: %s\n", library_version);
free(library_version);
}else{
printf("ERROR: Unable to get PiCode library version.\n");
result--;
}printf("\n");
/* Decode from pilight string */
char* pilight_string = (char*) "c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800@";
char* decoded_string = decodeString(pilight_string);
printf("String to decode: \"%s\"\n",pilight_string);
if (decoded_string){
printf("Decode string successful:\n");
printf("%s\n",decoded_string);free(decoded_string);
}else{
printf("ERROR: Unable to decode string.\n");
result--;
}/* Encode to pilight string from json */
char* json = (char*) "{ 'arctech_switch' : { 'id': 92, 'unit': 0, 'on': 1 }}";
uint8_t repeats = 5;char* encoded_json_string = encodeJson(json,repeats);
printf("\nJSON to encode: \"%s\"\n",json);
if (encoded_json_string){
printf("Encode successful:\n");
printf("%s\n",encoded_json_string);free(encoded_json_string);
}else{
printf("ERROR: Unable to encode JSON.\n");
result--;
}/* Encode from protocol name and json data to array of pulses if success */
char* protocol_name = (char*) "arctech_switch";
char* json_data = (char*) "{'id': 92, 'unit': 0, 'on': 1}";uint32_t* pulses = NULL;
uint16_t n_pulses_max = 0;
int n_pulses = 0;n_pulses_max = protocol_maxrawlen();
pulses = (uint32_t*)malloc(sizeof *pulses * (n_pulses_max + 1));
if (pulses != NULL){
printf("\nEncode protocol: \"%s\" JSON data: \"%s\"\n",protocol_name,json_data);
n_pulses = encodeToPulseTrainByName(pulses, n_pulses_max, protocol_name, json_data);if (n_pulses>0){
printf("Encode successful:\n");
printf("pulses[%d]={",n_pulses);
for (int i = 0; i