first commit
This commit is contained in:
104
ESP8266_DOMOTICZ_OCTOPRINT_WEB_VOLETS/Somfy.h
Normal file
104
ESP8266_DOMOTICZ_OCTOPRINT_WEB_VOLETS/Somfy.h
Normal file
@@ -0,0 +1,104 @@
|
||||
// -------------------------------------------------------------
|
||||
//
|
||||
// Fichier principal de votre Box compatible Somfy RTS ou Chacon Dio
|
||||
// Version 1.1.0
|
||||
// Mise à jour par TOST Corp. le 02 janvier 2020
|
||||
// www.tostcorp.com/boxsomfyrts
|
||||
//
|
||||
// -------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef Somfy_h
|
||||
#define Somfy_h
|
||||
|
||||
// Librairies utilisées
|
||||
#include <Arduino.h>
|
||||
// #include "sql_database_helper.h"
|
||||
#include <EEPROM.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include "PubSubClient.h"
|
||||
#include "Ticker_v2.h"
|
||||
// #include "config.h"
|
||||
|
||||
struct REMOTE {
|
||||
unsigned int id;
|
||||
char const* mqtt_topic;
|
||||
unsigned int default_rolling_code;
|
||||
uint32_t eeprom_address;
|
||||
char const* description;
|
||||
char const* device_group;
|
||||
};
|
||||
|
||||
struct DIO_REMOTE {
|
||||
unsigned int id;
|
||||
char const* mqtt_topic;
|
||||
unsigned long sender;
|
||||
unsigned long interruptor;
|
||||
char const* description;
|
||||
char const* device_group;
|
||||
};
|
||||
|
||||
|
||||
/* Adapted to run on ESP32 from original code at https://github.com/Nickduino/Somfy_Remote
|
||||
This program allows you to emulate a Somfy RTS or Simu HZ remote.
|
||||
If you want to learn more about the Somfy RTS protocol, check out https://pushstack.wordpress.com/somfy-rts-protocol/
|
||||
The rolling code will be stored in non-volatile storage (Preferences), so that you can power the Arduino off.
|
||||
Serial communication of the original code is replaced by MQTT over WiFi.
|
||||
Modifications should only be needed in config.h.
|
||||
*/
|
||||
|
||||
#define SIG_HIGH GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, 1 << PORT_TX)
|
||||
#define SIG_LOW GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, 1 << PORT_TX)
|
||||
|
||||
|
||||
|
||||
// void blink_function();
|
||||
// Ticker mqtt_error_timer(blink_function, 10, 11);
|
||||
// Ticker blink_timer(blink_function, 200, 21);
|
||||
// Ticker publish_timer(blink_function, 10, 11);
|
||||
|
||||
// WiFiClient wifiClient;
|
||||
|
||||
// Buttons
|
||||
#define SYMBOL 640
|
||||
#define HAUT 0x2
|
||||
#define STOP 0x1
|
||||
#define BAS 0x4
|
||||
#define PROG 0x8
|
||||
|
||||
|
||||
class Somfy {
|
||||
public:
|
||||
Somfy();
|
||||
void init();
|
||||
void loop();
|
||||
//void blink_function();
|
||||
|
||||
void BuildFrame(byte *frame, byte button, REMOTE remote);
|
||||
void receivedCallback(char* topic, byte* payload, unsigned int length);
|
||||
void mqttconnect();
|
||||
void send_somfy_command(char command, REMOTE currentRemote, bool group);
|
||||
void send_dio_command(char command, DIO_REMOTE dio_currentRemote, bool group);
|
||||
void SendCommand(byte *frame, byte sync);
|
||||
void blink_blue_light(int time_ms, int delay_ms);
|
||||
void sendBit(bool b);
|
||||
void sendPair(bool b);
|
||||
void transmit(unsigned long sender, int interruptor, int blnOn);
|
||||
int add_to_database(String device_id,const char* mqtt_topic, const char* description, const char* type, const char* device_group);
|
||||
int clean_database(String device_id);
|
||||
String urlencode(String str);
|
||||
unsigned char h2int(char c);
|
||||
void loopSerial();
|
||||
void _receivedCallback(char* topic, byte* payload, unsigned int length);
|
||||
|
||||
public:
|
||||
const char* HOST = "bipbipavertisseur.alwaysdata.net";
|
||||
byte frame[7];
|
||||
PubSubClient mqtt;
|
||||
WiFiClient wifiClient;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user