Esp32 compatibility (#145)
* esp32 init * RF gateway ok with ESP32 * correct IR gateway compilation errors and test RF2 ok * divide config per board type * update test file according user_config * differentiate variable type following IR libraries aka platforms * implement BLE beacons detection with ESP32 * Implement multitasking on BLE gateway * Library add and change core assignement * change core assignement for BLE * add mi flora value readings with ESP32 * adding some traces and removing unecessary comment * correct compilation error due to pin assignement * correct temperature float value and wrong mac adress rssi publishing * add esp32 to CI * correct esp32 ide retrieving * correcting paths * CI: correct architecture * libraries update (irremote) and overwrite ble library files
This commit is contained in:
1 parent
15cea6b222
commit
7c6e0ccf61
19 files changed
+319
-101
No files matched your search
@@ -25,3 +25,6 @@
|
||||
[submodule "libraries/NewRemoteSwitch"]
|
||||
path = libraries/NewRemoteSwitch
|
||||
url = https://github.com/1technophile/NewRemoteSwitch
|
||||
[submodule "libraries/ESP32_BLE_Arduino"]
|
||||
path = libraries/ESP32_BLE_Arduino
|
||||
url = git://github.com/nkolban/ESP32_BLE_Arduino.git
|
||||
+14
-4
@@ -5,19 +5,20 @@ env:
|
||||
- BD=arduino:avr:mega:cpu=atmega2560
|
||||
- BD=esp8266:esp8266:nodemcuv2:CpuFrequency=80,FlashSize=4M3M
|
||||
- BD=esp8266:esp8266:d1_mini:CpuFrequency=80,FlashSize=4M3M
|
||||
- BD=espressif:esp32:esp32doit-devkit-v1:FlashFreq=80
|
||||
before_install:
|
||||
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
|
||||
- sleep 3
|
||||
- export DISPLAY=:1.0
|
||||
- wget http://downloads.arduino.cc/arduino-1.8.2-linux64.tar.xz
|
||||
- tar xf arduino-1.8.2-linux64.tar.xz
|
||||
- sudo mv arduino-1.8.2 /usr/local/share/arduino
|
||||
- wget http://downloads.arduino.cc/arduino-1.8.5-linux64.tar.xz
|
||||
- tar xf arduino-1.8.5-linux64.tar.xz
|
||||
- sudo mv arduino-1.8.5 /usr/local/share/arduino
|
||||
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
|
||||
install:
|
||||
- ln -s $PWD /usr/local/share/arduino/OpenMQTTGateway
|
||||
- rm /usr/local/share/arduino/OpenMQTTGateway/User_config.h
|
||||
- cp /usr/local/share/arduino/OpenMQTTGateway/tests/Test_config.h /usr/local/share/arduino/OpenMQTTGateway/User_config.h
|
||||
- wget https://github.com/z3t0/Arduino-IRremote/archive/2.1.0.zip -O /tmp/IRremote.zip
|
||||
- wget https://github.com/z3t0/Arduino-IRremote/archive/v2.4.0.zip -O /tmp/IRremote.zip
|
||||
- unzip /tmp/IRremote.zip -d /usr/local/share/arduino/libraries
|
||||
- rm -rf /usr/local/share/arduino/libraries/RobotIRremote
|
||||
- wget https://github.com/markszabo/IRremoteESP8266/archive/v2.2.0.zip -O /tmp/IRremoteESP8266.zip
|
||||
@@ -37,6 +38,15 @@ install:
|
||||
- git clone https://github.com/LowPowerLab/RFM69 /usr/local/share/arduino/libraries/RFM69
|
||||
- rm /usr/local/share/arduino/libraries/RFM69/RFM69_OTA.h
|
||||
- rm /usr/local/share/arduino/libraries/RFM69/RFM69_OTA.cpp
|
||||
- git clone https://github.com/nkolban/ESP32_BLE_Arduino /usr/local/share/arduino/libraries/ESP32_BLE_Arduino
|
||||
- wget -q https://raw.githubusercontent.com/nkolban/esp32-snippets/master/cpp_utils/BLEAdvertisedDevice.cpp -O /usr/local/share/arduino/libraries/ESP32_BLE_Arduino/src/BLEAdvertisedDevice.cpp
|
||||
- wget -q https://raw.githubusercontent.com/nkolban/esp32-snippets/master/cpp_utils/BLEAdvertisedDevice.h -O /usr/local/share/arduino/libraries/ESP32_BLE_Arduino/src/BLEAdvertisedDevice.h
|
||||
- mkdir -p /usr/local/share/arduino/hardware/espressif
|
||||
- cd /usr/local/share/arduino/hardware/espressif
|
||||
- git clone https://github.com/espressif/arduino-esp32.git esp32
|
||||
- cd esp32/tools/
|
||||
- python get.py
|
||||
- cd /usr/local/share/arduino/OpenMQTTGateway
|
||||
- arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs
|
||||
- arduino --install-boards esp8266:esp8266
|
||||
- arduino --board $BD --save-prefs
|
||||
|
||||
+1
-1
@@ -441,7 +441,7 @@ void extract_char(char * token_char, char * subset, int start ,int l, boolean re
|
||||
if (reverse) revert_hex_data(tmp_subset, tmp_subset2, l+1);
|
||||
else strncpy( tmp_subset2, tmp_subset , l+1);
|
||||
long long_value = strtoul(tmp_subset2, NULL, 16);
|
||||
sprintf(tmp_subset2, "%d", long_value);
|
||||
sprintf(tmp_subset2, "%ld", long_value);
|
||||
strncpy( subset, tmp_subset2 , l+1);
|
||||
}else{
|
||||
if (reverse) revert_hex_data(tmp_subset, subset, l+1);
|
||||
|
||||
+23
-1
@@ -46,7 +46,7 @@
|
||||
|
||||
/*-------------DEFINE YOUR NETWORK PARAMETERS BELOW----------------*/
|
||||
// Update these with values suitable for your network.
|
||||
#ifdef ESP8266 // for nodemcu, weemos and esp8266
|
||||
#if defined(ESP8266) || defined(ESP32) // for nodemcu, weemos and esp8266
|
||||
#define wifi_ssid "wifi ssid"
|
||||
#define wifi_password "wifi password"
|
||||
#else // for arduino + W5100
|
||||
@@ -100,6 +100,28 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
||||
//#include "config_DHT.h"
|
||||
//#define ZgatewayRFM69 // If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
|
||||
//#include "config_RFM69.h"
|
||||
#elif ESP32
|
||||
#define ZgatewayRF
|
||||
#include "config_RF.h"
|
||||
#define ZgatewayRF2
|
||||
#define ZgatewayIR
|
||||
#include "config_IR.h"
|
||||
//#define ZgatewayBT
|
||||
//#include "config_BT.h"
|
||||
//#define ZsensorINA226
|
||||
//#include "config_INA226.h"
|
||||
//#define ZsensorHCSR501
|
||||
//#include "config_HCSR501.h"
|
||||
//#define ZsensorADC
|
||||
//#include "config_ADC.h"
|
||||
//#define ZsensorBH1750
|
||||
//#include "config_BH1750.h"
|
||||
//#define ZsensorBME280
|
||||
//#include "config_BME280.h"
|
||||
//#define ZsensorDHT // If you uncomment this you can't use I2C due to the fact that I2C use also D1
|
||||
//#include "config_DHT.h"
|
||||
//#define ZgatewayRFM69 // If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
|
||||
//#include "config_RFM69.h"
|
||||
#else // for arduino + W5100
|
||||
#define ZgatewayRF
|
||||
#include "config_RF.h"
|
||||
|
||||
+180
-69
@@ -27,6 +27,99 @@
|
||||
Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd https://github.com/dinosd/BLE_PROXIMITY for inspiring me how to implement the gateway
|
||||
*/
|
||||
#ifdef ZgatewayBT
|
||||
|
||||
#ifdef ESP32
|
||||
/*
|
||||
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
|
||||
Ported to Arduino ESP32 by Evandro Copercini
|
||||
*/
|
||||
// core task implementation thanks to https://techtutorialsx.com/2017/05/09/esp32-running-code-on-a-specific-core/
|
||||
|
||||
#include <BLEDevice.h>
|
||||
#include <BLEUtils.h>
|
||||
#include <BLEScan.h>
|
||||
#include <BLEAdvertisedDevice.h>
|
||||
|
||||
//core on which the BLE detection task will run
|
||||
static int taskCore = 0;
|
||||
|
||||
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
||||
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
||||
String mac_adress = advertisedDevice.getAddress().toString().c_str();
|
||||
mac_adress.replace(":","");
|
||||
mac_adress.toUpperCase();
|
||||
String mactopic = subjectBTtoMQTT + mac_adress;
|
||||
if (advertisedDevice.haveName()){
|
||||
String nameBLE = advertisedDevice.getName().c_str();
|
||||
trc(mactopic + " " + nameBLE);
|
||||
client.publish((char *)(mactopic + "/name").c_str(),(char *)nameBLE.c_str());
|
||||
}
|
||||
String rssi = String(advertisedDevice.getRSSI());
|
||||
trc(mactopic + " " + rssi);
|
||||
client.publish((char *)mactopic.c_str(),(char *)rssi.c_str());
|
||||
|
||||
if (advertisedDevice.haveServiceData()){
|
||||
trc(F("Get service data "));
|
||||
std::string serviceData = advertisedDevice.getServiceData();
|
||||
int serviceDataLength = serviceData.length();
|
||||
String returnedString = "";
|
||||
for (int i=0; i<serviceDataLength; i++)
|
||||
{
|
||||
int a = serviceData[i];
|
||||
if (a < 16) {
|
||||
returnedString = returnedString + "0";
|
||||
}
|
||||
returnedString = returnedString + String(a,HEX);
|
||||
}
|
||||
trc(returnedString);
|
||||
|
||||
trc(F("Get service data UUID"));
|
||||
BLEUUID serviceDataUUID = advertisedDevice.getServiceDataUUID();
|
||||
trc(serviceDataUUID.toString().c_str());
|
||||
|
||||
if (strstr(serviceDataUUID.toString().c_str(),"fe95") != NULL){
|
||||
trc("Processing mi flora data");
|
||||
char service_data[returnedString.length()+1];
|
||||
returnedString.toCharArray(service_data,returnedString.length()+1);
|
||||
service_data[returnedString.length()] = '\0';
|
||||
char mac[mac_adress.length()+1];
|
||||
mac_adress.toCharArray(mac,mac_adress.length()+1);
|
||||
boolean result = process_miflora_data(-22,service_data,mac);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void setupBT(){
|
||||
// we setup a task with priority one to avoid conflict with other gateways
|
||||
xTaskCreatePinnedToCore(
|
||||
coreTask, /* Function to implement the task */
|
||||
"coreTask", /* Name of the task */
|
||||
10000, /* Stack size in words */
|
||||
NULL, /* Task input parameter */
|
||||
1, /* Priority of the task */
|
||||
NULL, /* Task handle. */
|
||||
taskCore); /* Core where the task should run */
|
||||
}
|
||||
|
||||
void coreTask( void * pvParameters ){
|
||||
|
||||
String taskMessage = "BT Task running on core ";
|
||||
taskMessage = taskMessage + xPortGetCoreID();
|
||||
|
||||
while(true){
|
||||
trc(taskMessage);
|
||||
delay(TimeBtw_Read);
|
||||
BLEDevice::init("");
|
||||
BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan
|
||||
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
|
||||
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
|
||||
BLEScanResults foundDevices = pBLEScan->start(Scan_duration);
|
||||
}
|
||||
}
|
||||
|
||||
#else // arduino or ESP8266 working with HM10/11
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define STRING_MSG "OK+DISC:"
|
||||
@@ -67,40 +160,43 @@ boolean BTtoMQTT() {
|
||||
|
||||
if (millis() > (timebt + TimeBtw_Read)) {//retriving data
|
||||
timebt = millis();
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266)
|
||||
yield();
|
||||
#endif
|
||||
if (returnedString != "") {
|
||||
size_t pos = 0;
|
||||
while ((pos = returnedString.lastIndexOf(delimiter)) != -1) {
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266)
|
||||
yield();
|
||||
#endif
|
||||
String token = returnedString.substring(pos);
|
||||
trc(token);
|
||||
returnedString.remove(pos,returnedString.length() );
|
||||
char token_char[token.length()+1];
|
||||
token.toCharArray(token_char, token.length()+1);
|
||||
|
||||
for(int i =0; i<6;i++)
|
||||
{
|
||||
extract_char(token_char,d[i].extract,d[i].start, d[i].len ,d[i].reverse, false);
|
||||
if (i == 3) d[5].len = (int)strtol(d[i].extract, NULL, 16) * 2; // extracting the length of the rest data
|
||||
}
|
||||
|
||||
if((strlen(d[0].extract)) == 12) // if a mac adress is detected we publish it
|
||||
{
|
||||
strupp(d[0].extract);
|
||||
String mactopic(d[0].extract);
|
||||
trc(mactopic);
|
||||
mactopic = subjectBTtoMQTT + mactopic;
|
||||
int rssi = (int)strtol(d[2].extract, NULL, 16) - 256;
|
||||
char val[12];
|
||||
sprintf(val, "%d", rssi);
|
||||
client.publish((char *)mactopic.c_str(),val);
|
||||
if (strcmp(d[4].extract, "fe95") == 0)
|
||||
boolean result = process_miflora_data(d[5].extract,d[0].extract);
|
||||
|
||||
return true;
|
||||
trc(token);
|
||||
if ( token.length() > 60){// we extract data only if we have detailled infos
|
||||
for(int i =0; i<6;i++)
|
||||
{
|
||||
extract_char(token_char,d[i].extract,d[i].start, d[i].len ,d[i].reverse, false);
|
||||
if (i == 3) d[5].len = (int)strtol(d[i].extract, NULL, 16) * 2; // extracting the length of the rest data
|
||||
}
|
||||
|
||||
if((strlen(d[0].extract)) == 12) // if a mac adress is detected we publish it
|
||||
{
|
||||
strupp(d[0].extract);
|
||||
String mactopic(d[0].extract);
|
||||
trc(mactopic);
|
||||
mactopic = subjectBTtoMQTT + mactopic;
|
||||
int rssi = (int)strtol(d[2].extract, NULL, 16) - 256;
|
||||
char val[12];
|
||||
sprintf(val, "%d", rssi);
|
||||
client.publish((char *)mactopic.c_str(),val);
|
||||
if (strcmp(d[4].extract, "fe95") == 0)
|
||||
boolean result = process_miflora_data(0,d[5].extract,d[0].extract);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
returnedString = ""; //init data string
|
||||
@@ -119,56 +215,13 @@ void strupp(char* beg)
|
||||
++beg;
|
||||
}
|
||||
|
||||
boolean process_miflora_data(char * rest_data, char * mac_adress){
|
||||
|
||||
char tmp_rest_data_length[1];
|
||||
memcpy( tmp_rest_data_length, &rest_data[51], 1 );
|
||||
int data_length = ((int)strtol(tmp_rest_data_length, NULL, 16)*2)+1;
|
||||
char rev_data[data_length];
|
||||
char data[data_length];
|
||||
memcpy( rev_data, &rest_data[52], data_length );
|
||||
rev_data[data_length] = '\0';
|
||||
|
||||
// reverse data order
|
||||
revert_hex_data(rev_data, data, data_length);
|
||||
int value = strtol(data, NULL, 16);
|
||||
char val[12];
|
||||
sprintf(val, "%d", value);
|
||||
String mactopic(mac_adress);
|
||||
mactopic = subjectBTtoMQTT + mactopic;
|
||||
|
||||
|
||||
// following the value of digit 47 we determine the type of data we get from the sensor
|
||||
switch (rest_data[47]) {
|
||||
case '9' :
|
||||
mactopic = mactopic + "/" + "fer";
|
||||
break;
|
||||
case '4' :
|
||||
mactopic = mactopic + "/" + "tem";
|
||||
dtostrf(value/10,4,1,val); // override temperature value in case we have, indeed temp has to be divided by 10
|
||||
break;
|
||||
case '7' :
|
||||
mactopic = mactopic + "/" + "lux";
|
||||
break;
|
||||
case '8' :
|
||||
mactopic = mactopic + "/" + "hum";
|
||||
break;
|
||||
default:
|
||||
trc("can't read values");
|
||||
return false;
|
||||
}
|
||||
client.publish((char *)mactopic.c_str(),val);;
|
||||
trc(String(val));
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef ZgatewayBT_v6xx
|
||||
#define QUESTION_MSG "AT+DISI?"
|
||||
boolean BTtoMQTT() {
|
||||
while (softserial.available() > 0) {
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266)
|
||||
yield();
|
||||
#endif
|
||||
String discResult = softserial.readString();
|
||||
@@ -178,7 +231,7 @@ boolean BTtoMQTT() {
|
||||
float device_number = discResult.length()/78.0;
|
||||
if (device_number == (int)device_number){ // to avoid publishing partial values we detect if the serial data has been fully read = a multiple of 78
|
||||
trc(F("Sending BT data to MQTT"));
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266)
|
||||
yield();
|
||||
#endif
|
||||
for (int i=0;i<(int)device_number;i++){
|
||||
@@ -201,7 +254,7 @@ boolean BTtoMQTT() {
|
||||
}
|
||||
if (millis() > (timebt + TimeBtw_Read)) {//retriving value of adresses and rssi
|
||||
timebt = millis();
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266)
|
||||
yield();
|
||||
#endif
|
||||
softserial.print(F(QUESTION_MSG));
|
||||
@@ -211,3 +264,61 @@ boolean BTtoMQTT() {
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
boolean process_miflora_data(int offset, char * rest_data, char * mac_adress){
|
||||
|
||||
int data_length = 0;
|
||||
switch (rest_data[51 + offset]) {
|
||||
case '1' :
|
||||
case '2' :
|
||||
case '3' :
|
||||
case '4' :
|
||||
data_length = ((rest_data[51 + offset] - '0') * 2)+1;
|
||||
trc(String(data_length));
|
||||
break;
|
||||
default:
|
||||
trc("can't read data_length");
|
||||
return false;
|
||||
}
|
||||
|
||||
char rev_data[data_length];
|
||||
char data[data_length];
|
||||
memcpy( rev_data, &rest_data[52 + offset], data_length );
|
||||
rev_data[data_length] = '\0';
|
||||
|
||||
// reverse data order
|
||||
revert_hex_data(rev_data, data, data_length);
|
||||
double value = strtol(data, NULL, 16);
|
||||
trc(String(value));
|
||||
char val[12];
|
||||
String mactopic(mac_adress);
|
||||
mactopic = subjectBTtoMQTT + mactopic;
|
||||
|
||||
// following the value of digit 47 we determine the type of data we get from the sensor
|
||||
switch (rest_data[47 + offset]) {
|
||||
case '9' :
|
||||
mactopic = mactopic + "/" + "fer";
|
||||
dtostrf(value,0,0,val);
|
||||
break;
|
||||
case '4' :
|
||||
mactopic = mactopic + "/" + "tem";
|
||||
dtostrf(value/10,3,1,val); // temp has to be divided by 10
|
||||
break;
|
||||
case '7' :
|
||||
mactopic = mactopic + "/" + "lux";
|
||||
dtostrf(value,0,0,val);
|
||||
break;
|
||||
case '8' :
|
||||
mactopic = mactopic + "/" + "hum";
|
||||
dtostrf(value,0,0,val);
|
||||
break;
|
||||
default:
|
||||
trc("can't read values");
|
||||
return false;
|
||||
}
|
||||
client.publish((char *)mactopic.c_str(),val);;
|
||||
trc(String(val));
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
+27
-8
@@ -41,19 +41,31 @@
|
||||
|
||||
void setupIR()
|
||||
{
|
||||
|
||||
//IR init parameters
|
||||
#ifdef ESP8266
|
||||
irsend.begin();
|
||||
#endif
|
||||
|
||||
irrecv.enableIRIn(); // Start the receiver
|
||||
irrecv.enableIRIn(); // Start the receiver
|
||||
|
||||
trc(F("IR_EMITTER_PIN "));
|
||||
trc(String(IR_EMITTER_PIN));
|
||||
trc(F("IR_RECEIVER_PIN "));
|
||||
trc(String(IR_RECEIVER_PIN));
|
||||
trc(F("ZgatewayIR setup done "));
|
||||
|
||||
}
|
||||
boolean IRtoMQTT(){
|
||||
decode_results results;
|
||||
|
||||
if (irrecv.decode(&results)){
|
||||
trc(F("Rcv. IR"));
|
||||
#ifdef ESP32
|
||||
String taskMessage = "Task running on core ";
|
||||
taskMessage = taskMessage + xPortGetCoreID();
|
||||
trc(taskMessage);
|
||||
#endif
|
||||
unsigned long MQTTvalue = 0;
|
||||
String MQTTprotocol;
|
||||
String MQTTbits;
|
||||
@@ -74,12 +86,15 @@ boolean IRtoMQTT(){
|
||||
trc(rawCode);
|
||||
// if needed we directly resend the raw code
|
||||
if (RawDirectForward){
|
||||
uint16_t rawsend[results.rawlen];
|
||||
for (uint16_t i = 1; i < results.rawlen; i++) {
|
||||
#ifdef ESP8266
|
||||
if (i % 100 == 0) yield(); // Preemptive yield every 100th entry to feed the WDT.
|
||||
#endif
|
||||
rawsend[i] = results.rawbuf[i];
|
||||
#ifdef ESP8266
|
||||
uint16_t rawsend[results.rawlen];
|
||||
for (uint16_t i = 1; i < results.rawlen; i++) {
|
||||
if (i % 100 == 0) yield(); // Preemptive yield every 100th entry to feed the WDT.
|
||||
#else
|
||||
unsigned int rawsend[results.rawlen];
|
||||
for (int i = 1; i < results.rawlen; i++) {
|
||||
#endif
|
||||
rawsend[i] = results.rawbuf[i];
|
||||
}
|
||||
irsend.sendRaw(rawsend, results.rawlen, RawFrequency);
|
||||
trc(F("raw signal redirected"));
|
||||
@@ -154,7 +169,11 @@ void MQTTtoIR(char * topicOri, char * datacallback) {
|
||||
else if(strstr(topicOri, "IR_Raw") != NULL){ // sending Raw data
|
||||
trc("IR_Raw");
|
||||
//buffer allocation from char datacallback
|
||||
uint16_t Raw[count+1];
|
||||
#ifdef ESP8266
|
||||
uint16_t Raw[count+1];
|
||||
#else
|
||||
unsigned int Raw[count+1];
|
||||
#endif
|
||||
String value = "";
|
||||
int j = 0;
|
||||
for(int i = 0; i < s; i++)
|
||||
|
||||
+10
-1
@@ -35,15 +35,24 @@ void setupRF(){
|
||||
|
||||
//RF init parameters
|
||||
mySwitch.enableTransmit(RF_EMITTER_PIN);
|
||||
trc(F("RF_EMITTER_PIN "));
|
||||
trc(String(RF_EMITTER_PIN));
|
||||
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT);
|
||||
mySwitch.enableReceive(RF_RECEIVER_PIN);
|
||||
|
||||
trc(F("RF_RECEIVER_PIN "));
|
||||
trc(String(RF_RECEIVER_PIN));
|
||||
trc(F("ZgatewayRF setup done "));
|
||||
}
|
||||
|
||||
boolean RFtoMQTT(){
|
||||
|
||||
if (mySwitch.available()){
|
||||
trc(F("Rcv. RF"));
|
||||
#ifdef ESP32
|
||||
String taskMessage = "RF Task running on core ";
|
||||
taskMessage = taskMessage + xPortGetCoreID();
|
||||
trc(taskMessage);
|
||||
#endif
|
||||
unsigned long MQTTvalue = 0;
|
||||
String MQTTprotocol;
|
||||
String MQTTbits;
|
||||
|
||||
+6
-3
@@ -52,11 +52,14 @@ RF2rxd rf2rd;
|
||||
void setupRF2(){
|
||||
#ifndef ZgatewayRF //receiving with RF2 is not compatible with ZgatewayRF
|
||||
NewRemoteReceiver::init(RF_RECEIVER_PIN, 2, rf2Callback);
|
||||
trc(F("Receiver RF2 initialized"));
|
||||
trc(F("RF_EMITTER_PIN "));
|
||||
trc(String(RF_EMITTER_PIN));
|
||||
trc(F("RF_RECEIVER_PIN "));
|
||||
trc(String(RF_RECEIVER_PIN));
|
||||
trc(F("ZgatewayRF2 setup done "));
|
||||
#endif
|
||||
pinMode(RF_EMITTER_PIN, OUTPUT);
|
||||
digitalWrite(RF_EMITTER_PIN, LOW);
|
||||
trc(F("Transmitter RF2 initialized"));
|
||||
digitalWrite(RF_EMITTER_PIN, LOW);
|
||||
}
|
||||
|
||||
boolean RF2toMQTT(){
|
||||
|
||||
+4
-4
@@ -65,7 +65,7 @@ uint32_t gc_checksum() {
|
||||
return checksum;
|
||||
}
|
||||
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
void eeprom_setup() {
|
||||
EEPROM.begin(4096);
|
||||
pGC = (struct _GLOBAL_CONFIG *)EEPROM.getDataPtr();
|
||||
@@ -88,7 +88,7 @@ void eeprom_setup() {
|
||||
RFM69 radio;
|
||||
|
||||
void setupRFM69(void) {
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
eeprom_setup();
|
||||
#endif
|
||||
int freq;
|
||||
@@ -101,7 +101,7 @@ void setupRFM69(void) {
|
||||
// Initialize radio
|
||||
if (!radio.initialize(pGC->rfmfrequency, pGC->nodeid, pGC->networkid))
|
||||
{
|
||||
trc(F("RFM69 initialization failed"));
|
||||
trc(F("ZgatewayRFM69 initialization failed"));
|
||||
}
|
||||
|
||||
if (GC_IS_RFM69HCW) {
|
||||
@@ -111,7 +111,7 @@ void setupRFM69(void) {
|
||||
|
||||
if (pGC->encryptkey[0] != '\0') radio.encrypt(pGC->encryptkey);
|
||||
|
||||
trc(F("RFM69 Listening and transmitting at"));
|
||||
trc(F("ZgatewayRFM69 Listening and transmitting at"));
|
||||
switch (pGC->rfmfrequency) {
|
||||
case RF69_433MHZ:
|
||||
freq = 433;
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@
|
||||
*/
|
||||
#ifdef ZsensorADC
|
||||
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
ADC_MODE(ADC_TOUT);
|
||||
#endif
|
||||
|
||||
@@ -40,7 +40,7 @@ void MeasureADC(){
|
||||
timeadc = millis();
|
||||
static int persistedadc;
|
||||
int val = analogRead(ADC_PIN);
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
yield();
|
||||
#endif
|
||||
if (isnan(val)) {
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ void MeasureHCSR501(){
|
||||
if (millis() > TimeBeforeStartHCSR501) {//let time to init the PIR sensor
|
||||
static int pirState = LOW;
|
||||
int PresenceValue = digitalRead(HCSR501_PIN);
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
yield();
|
||||
#endif
|
||||
if (PresenceValue == HIGH) {
|
||||
|
||||
+5
-1
@@ -25,7 +25,8 @@
|
||||
*/
|
||||
/*----------------------BT topics & parameters-------------------------*/
|
||||
#define subjectBTtoMQTT "home/BTtoMQTT/"
|
||||
#define TimeBtw_Read 10000 //define the time between 2 scans
|
||||
#define TimeBtw_Read 20000 //define the time between 2 scans
|
||||
#define Scan_duration 10 //define the time for a scan
|
||||
#define HM-10
|
||||
//#define HM-11 // uncomment this line if you use HM-11 and comment the line above
|
||||
#define ZgatewayBT_v6xx // comment if you don't have a firmware version of HM10/11 >= v601
|
||||
@@ -45,6 +46,9 @@ struct decompose
|
||||
#ifdef ESP8266
|
||||
#define BT_RX 13 //D7 ESP8266 RX connect HM-10 or 11 TX
|
||||
#define BT_TX 12 //D6 ESP8266 TX connect HM-10 or 11 RX
|
||||
#elif defined(ESP32)
|
||||
#define BT_RX 18 // not tested
|
||||
#define BT_TX 19 // not tested
|
||||
#else
|
||||
#define BT_RX 5 //arduino RX connect HM-10 or 11 TX
|
||||
#define BT_TX 6 //arduino TX connect HM-10 or 11 RX
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@
|
||||
#define dht_always true // if false when the current value for temp or hum is the same as previous one don't send it by MQTT
|
||||
#define TimeBetweenReadingDHT 30000 // time between 2 DHT readings
|
||||
/*-------------------PIN DEFINITIONS----------------------*/
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
#define DHT_RECEIVER_PIN D1 // you can put D5 if you don't use HCSR501 sensor and the RFM69
|
||||
#else
|
||||
#define DHT_RECEIVER_PIN 8
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
#define TimeBeforeStartHCSR501 60000 //define the time necessary for HC SR501 init
|
||||
|
||||
/*-------------------PIN DEFINITIONS----------------------*/
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
#define HCSR501_PIN D5
|
||||
#else
|
||||
#define HCSR501_PIN D7
|
||||
|
||||
+13
-1
@@ -57,6 +57,15 @@
|
||||
#define IR_SAMSUNG
|
||||
#define IR_PANASONIC
|
||||
#define IR_RCMM
|
||||
#elif ESP32
|
||||
#define IR_Raw
|
||||
#define IR_COOLIX
|
||||
#define IR_Whynter
|
||||
#define IR_LG
|
||||
#define IR_DISH
|
||||
#define IR_RC5
|
||||
#define IR_Sharp
|
||||
#define IR_SAMSUNG
|
||||
#else //IR supported protocols on arduino uncomment if you want to send with this protocol, NEC protocol is available per default
|
||||
//#define IR_COOLIX
|
||||
//#define IR_Whynter
|
||||
@@ -74,8 +83,11 @@
|
||||
#ifdef ESP8266
|
||||
#define IR_RECEIVER_PIN 2
|
||||
#define IR_EMITTER_PIN 16
|
||||
#elif ESP32
|
||||
#define IR_RECEIVER_PIN 27
|
||||
#define IR_EMITTER_PIN 14
|
||||
#else
|
||||
#define IR_RECEIVER_PIN 0 // 0 = D2 on arduino
|
||||
#define IR_EMITTER_PIN D9
|
||||
#define IR_EMITTER_PIN 9
|
||||
#endif
|
||||
|
||||
+3
-1
@@ -64,6 +64,9 @@ RF supported protocols
|
||||
#ifdef ESP8266
|
||||
#define RF_RECEIVER_PIN 0 // D3 on nodemcu
|
||||
#define RF_EMITTER_PIN 3 // RX on nodemcu
|
||||
#elif defined(ESP32)
|
||||
#define RF_RECEIVER_PIN 13 // D13 on DOIT ESP32
|
||||
#define RF_EMITTER_PIN 12 // D12 on DOIT ESP32
|
||||
#else
|
||||
//IMPORTANT NOTE: On arduino UNO connect IR emitter pin to D9 , comment #define IR_USE_TIMER2 and uncomment #define IR_USE_TIMER1 on library <library>IRremote/IRremoteInt.h so as to free pin D3 for RF RECEIVER PIN
|
||||
//RF PIN definition
|
||||
@@ -71,4 +74,3 @@ RF supported protocols
|
||||
#define RF_EMITTER_PIN 4 //4 = D4 on arduino
|
||||
#endif
|
||||
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ const char PROGMEM RFM69AP_NAME[] = "RFM69-AP";
|
||||
#define POWER_LEVEL 31
|
||||
|
||||
/*-------------------PIN DEFINITIONS----------------------*/
|
||||
#ifdef ESP8266
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
#define RFM69_CS D1
|
||||
#define RFM69_IRQ D8 // GPIO15/D8
|
||||
#define RFM69_IRQN digitalPinToInterrupt(RFM69_IRQ)
|
||||
|
||||
Submodule
+1
Submodule libraries/ESP32_BLE_Arduino added at f8fe9d7cdf.
+23
-1
@@ -46,7 +46,7 @@
|
||||
|
||||
/*-------------DEFINE YOUR NETWORK PARAMETERS BELOW----------------*/
|
||||
// Update these with values suitable for your network.
|
||||
#ifdef ESP8266 // for nodemcu, weemos and esp8266
|
||||
#if defined(ESP8266) || defined(ESP32) // for nodemcu, wemos, esp32 and esp8266
|
||||
#define wifi_ssid "wifi ssid"
|
||||
#define wifi_password "wifi password"
|
||||
#else // for arduino + W5100
|
||||
@@ -99,6 +99,28 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
||||
#include "config_DHT.h"
|
||||
#define ZgatewayRFM69 // If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
|
||||
#include "config_RFM69.h"
|
||||
#elif ESP32
|
||||
#define ZgatewayRF
|
||||
#include "config_RF.h"
|
||||
#define ZgatewayRF2
|
||||
//#define ZgatewayIR
|
||||
//#include "config_IR.h"
|
||||
#define ZgatewayBT
|
||||
#include "config_BT.h"
|
||||
//#define ZsensorINA226
|
||||
//#include "config_INA226.h"
|
||||
//#define ZsensorHCSR501
|
||||
//#include "config_HCSR501.h"
|
||||
//#define ZsensorADC
|
||||
//#include "config_ADC.h"
|
||||
//#define ZsensorBH1750
|
||||
//#include "config_BH1750.h"
|
||||
//#define ZsensorBME280
|
||||
//#include "config_BME280.h"
|
||||
//#define ZsensorDHT // If you uncomment this you can't use I2C due to the fact that I2C use also D1
|
||||
//#include "config_DHT.h"
|
||||
//#define ZgatewayRFM69 // If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
|
||||
//#include "config_RFM69.h"
|
||||
#else // for arduino + W5100
|
||||
#define ZgatewayRF
|
||||
#include "config_RF.h"
|
||||
|
||||
Reference in new issue
Block a user