Skip to content

Commit

Permalink
Removed Autoconnect from master
Browse files Browse the repository at this point in the history
  • Loading branch information
couin3 committed Sep 21, 2020
1 parent b7d82e8 commit cf3bd48
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 1,108 deletions.
5 changes: 1 addition & 4 deletions RFLink/1_Radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
#include "RFLink.h"
#include "1_Radio.h"
#include "4_Display.h"
#ifdef AUTOCONNECT_ENABLED
#include "9_AutoConnect.h"
#else

uint8_t PIN_RF_RX_PMOS = PIN_RF_RX_PMOS_0;
uint8_t PIN_RF_RX_NMOS = PIN_RF_RX_NMOS_0;
uint8_t PIN_RF_RX_VCC = PIN_RF_RX_VCC_0;
Expand All @@ -25,7 +23,6 @@ uint8_t PIN_RF_TX_VCC = PIN_RF_TX_VCC_0;
uint8_t PIN_RF_TX_GND = PIN_RF_TX_GND_0;
uint8_t PIN_RF_TX_NA = PIN_RF_TX_NA_0;
uint8_t PIN_RF_TX_DATA = PIN_RF_TX_DATA_0;
#endif //AUTOCONNECT_ENABLED

Radio_State current_State = Radio_NA;

Expand Down
30 changes: 0 additions & 30 deletions RFLink/3_Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,6 @@ boolean CheckMQTT(byte *byte_in)
return false;
}

#ifdef AUTOCONNECT_ENABLED
boolean CheckWeb(String &String_in)
{
if (!String_in.isEmpty())
{
String_in.trim();
char char_in[INPUT_COMMAND_SIZE];
String_in.toCharArray(char_in, String_in.length() + 1);
char_in[String_in.length() + 1] = 0;

if (CopySerial(char_in))
{
#ifdef SERIAL_ENABLED
Serial.flush();
Serial.print(F("Message arrived [Web] "));
Serial.println(InputBuffer_Serial);
#endif
if (CheckCmd())
{
String_in.clear();
return true;
}
}
String_in.clear();
return false;
}
return false;
}
#endif // AUTOCONNECT_ENABLED

boolean CopySerial(char *src)
{
return (strncpy(InputBuffer_Serial, src, INPUT_COMMAND_SIZE - 2));
Expand Down
3 changes: 0 additions & 3 deletions RFLink/3_Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@ extern char InputBuffer_Serial[INPUT_COMMAND_SIZE];

boolean CheckSerial();
boolean CheckMQTT(byte *);
#ifdef AUTOCONNECT_ENABLED
boolean CheckWeb(String &);
#endif // AUTOCONNECT_ENABLED
#endif
48 changes: 0 additions & 48 deletions RFLink/5_Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@
#include "RFLink.h"
#include "2_Signal.h"
#include "5_Plugin.h"
#ifdef AUTOCONNECT_ENABLED
#include "9_AutoConnect.h"
#ifdef ESP8266
#include <FS.h>
#include <LittleFS.h>
#elif ESP32
#include <SPIFFS.h>
#define LittleFS SPIFFS
#endif // ESP8266
#include <ArduinoJson.h>
#endif // AUTOCONNECT

boolean (*Plugin_ptr[PLUGIN_MAX])(byte, char *); // Receive plugins
byte Plugin_id[PLUGIN_MAX];
Expand Down Expand Up @@ -1695,43 +1684,6 @@ void PluginInit(void)
Plugin_ptr[x++] = &Plugin_255;
#endif

// read config file to desactivated protocols
#ifdef AUTOCONNECT_ENABLED
LittleFS.begin();
Serial.print("Param ");
Serial.print(PROTOCOL_FILE);
Serial.print(F(" :\t"));
File configFile = LittleFS.open(PROTOCOL_FILE, "r");
if (configFile)
{
// const int capacity = JSON_ARRAY_SIZE(254) + 2 * JSON_OBJECT_SIZE(2); // 4128
// StaticJsonDocument<4128> doc;
DynamicJsonDocument doc(4128);

if (deserializeJson(doc, configFile))
{
Serial.println(F("Failed to load"));
}
else
{
for (x = 0; x < PLUGIN_MAX; x++)
{
if (doc[x][String(Plugin_id[x])] == 0)
Plugin_State[x] = P_Disabled;
}
Serial.println(F("Loaded"));
}
doc.clear();
configFile.close();
}
else
{
Serial.println(F("Failed to open(+r)"));
}
LittleFS.end();

#endif // AUTOCONNECT_ENABLED

// Initialiseer alle plugins door aanroep met verwerkingsparameter PLUGIN_INIT
PluginInitCall(0, 0);
}
Expand Down
2 changes: 0 additions & 2 deletions RFLink/6_Credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#define CREDENTIALS_h

#include "RFLink.h"
#ifndef AUTOCONNECT_ENABLED

// local AP
String WIFI_SSID = "your_AP_ssid";
Expand All @@ -36,5 +35,4 @@ String MQTT_TOPIC_OUT = "/RFLink/msg";
String MQTT_TOPIC_IN = "/RFLink/cmd";
String MQTT_TOPIC_LWT = "/RFLink/lwt";

#endif
#endif
27 changes: 3 additions & 24 deletions RFLink/6_WiFi_MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@
#include "3_Serial.h"
#include "4_Display.h"
#include "6_WiFi_MQTT.h"
#ifdef AUTOCONNECT_ENABLED
#include "9_AutoConnect.h"
#else
#include "6_Credentials.h"
#endif

#ifndef AUTOCONNECT_ENABLED
#ifdef ESP32
#include <WiFi.h>
#elif ESP8266
#include <ESP8266WiFi.h>
#endif
#endif // !AUTOCONNECT_ENABLED

#ifdef MQTT_ENABLED

Expand All @@ -42,7 +36,6 @@ PubSubClient MQTTClient; // MQTTClient(WIFIClient);

void callback(char *, byte *, unsigned int);

#ifndef AUTOCONNECT_ENABLED
static String WIFI_PWR = String(WIFI_PWR_0);

void setup_WIFI()
Expand Down Expand Up @@ -78,7 +71,6 @@ void setup_WIFI()
Serial.print(F("WiFi RSSI :\t\t"));
Serial.println(WiFi.RSSI());
}
#endif

void setup_MQTT()
{
Expand All @@ -97,12 +89,7 @@ void callback(char *topic, byte *payload, unsigned int length)
}

void reconnect()
{ // MQTT connection (documented way from AutoConnect : https://github.com/Hieromon/AutoConnect/tree/master/examples/mqttRSSI_NA)

#ifdef AUTOCONNECT_ENABLED
uint8_t retry = 3;
#endif // AUTOCONNECT_ENABLED

{
bResub = true;
while (!MQTTClient.connected())
{
Expand All @@ -129,25 +116,17 @@ void reconnect()
{
Serial.print(F("Failed - rc="));
Serial.println(MQTTClient.state());
#ifdef AUTOCONNECT_ENABLED
if (!--retry)
break;
delay(500);
#else // AUTOCONNECT_ENABLED
Serial.println(F("MQTT Retry :\tTry again in 5 seconds"));
// Wait 5 seconds before retrying
for (byte i = 0; i < 10; i++)
delay(500); // delay(5000) may cause hang
#endif // AUTOCONNECT_ENABLED
}
}
}

void publishMsg()
{
#ifndef AUTOCONNECT_ENABLED
static boolean MQTT_RETAINED = MQTT_RETAINED_0;
#endif // !AUTOCONNECT_ENABLED

if (!MQTTClient.connected())
reconnect();
Expand All @@ -174,9 +153,9 @@ void checkMQTTloop()
lastCheck = millis();
}
}
#endif // MQTT_ENABLED

#if (!defined(AUTOCONNECT_ENABLED) && !defined(MQTT_ENABLED))
#else // MQTT_ENABLED

#if (defined(ESP32) || defined(ESP8266))
void setup_WIFI_OFF()
{
Expand Down
23 changes: 4 additions & 19 deletions RFLink/6_WiFi_MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,27 @@
#include <Arduino.h>
#include "RFLink.h"

#ifdef AUTOCONNECT_ENABLED
extern String MQTT_SERVER;
extern String MQTT_PORT;
extern String MQTT_ID;
extern String MQTT_USER;
extern String MQTT_PSWD;
extern String MQTT_TOPIC_OUT;
extern String MQTT_TOPIC_IN;
extern boolean MQTT_RETAINED;
extern String Adv_HostName;
extern String Adv_Power;
#else
#ifdef ESP32
#include <WiFi.h>
#elif ESP8266
#include <ESP8266WiFi.h>
#endif
#endif // AUTOCONNECT_ENABLED

#ifdef MQTT_ENABLED
extern char MQTTbuffer[PRINT_BUFFER_SIZE]; // Buffer for MQTT message

#ifndef AUTOCONNECT_ENABLED
void setup_WIFI();
#endif // !AUTOCONNECT_ENABLED

void setup_MQTT();
void reconnect();
void publishMsg();
void checkMQTTloop();
#endif // MQTT_ENABLED

#if (!defined(AUTOCONNECT_ENABLED) && !defined(MQTT_ENABLED))
#else // MQTT_ENABLED

#if (defined(ESP32) || defined(ESP8266))
void setup_WIFI_OFF();
#endif
#endif

#endif // MQTT_ENABLED

#endif // WiFi_MQTT_h
Loading

0 comments on commit cf3bd48

Please sign in to comment.