Change to WifiMan
This commit is contained in:
parent
f8bef348e2
commit
77e7edd5e9
|
@ -8,26 +8,17 @@
|
|||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:ttgo-t-beam]
|
||||
platform = espressif32
|
||||
board = ttgo-t-beam
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
knolleary/PubSubClient@^2.8
|
||||
extentsoftware/TBeamPower@^2.0.4
|
||||
peterus/esp-logger @ 0.0.1
|
||||
bblanchon/ArduinoJson@^6.19.4
|
||||
olikraus/U8g2@^2.33.12
|
||||
monitor_speed = 115200
|
||||
[platformio]
|
||||
default_envs = nodemcuv2
|
||||
|
||||
[env:esp8266]
|
||||
[env:nodemcuv2]
|
||||
platform = espressif8266
|
||||
board = esp12e
|
||||
board = nodemcuv2
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
knolleary/PubSubClient@^2.8
|
||||
peterus/esp-logger @ 0.0.1
|
||||
bblanchon/ArduinoJson@^6.19.4
|
||||
olikraus/U8g2@^2.33.12
|
||||
olikraus/U8g2@^2.34.4
|
||||
tzapu/WiFiManager@^0.16.0
|
||||
monitor_speed = 115200
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
//U8G2_SSD1306_128X64_VCOMH0_F_HW_I2C display(U8G2_R0, OLED_RST, OLED_SCL, OLED_SDA); OLED on TTGO
|
||||
U8G2_ST7920_128X64_F_HW_SPI display(U8G2_R2, LCD_CS, U8X8_PIN_NONE);
|
||||
//U8G2_ST7920_128X64_F_2ND_HW_SPI display(U8G2_R2, LCD_CS, U8X8_PIN_NONE);
|
||||
//U8G2_ST7920_128X64_F_SW_SPI display(U8G2_R2, LCD_E_SCLK, LCD_RW_SI, LCD_CS, U8X8_PIN_NONE);
|
||||
|
||||
bool pv_charging = false;
|
||||
|
@ -61,7 +62,7 @@ void display_wifi(char* STATUS) {
|
|||
do {
|
||||
display_header();
|
||||
display.drawStr(0,52,"Connecting wifi...");
|
||||
display.drawStr(30,60, STATUS);
|
||||
display.drawStr(0,60, STATUS);
|
||||
} while ( display.nextPage() );
|
||||
}
|
||||
|
||||
|
|
35
src/main.cpp
35
src/main.cpp
|
@ -26,6 +26,9 @@
|
|||
#include <logger.h>
|
||||
//#include <WiFi.h> -ESP32
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <Wire.h>
|
||||
|
@ -33,19 +36,19 @@
|
|||
|
||||
//Program parts
|
||||
#include <pins.h>
|
||||
#include <screens.h>
|
||||
//#include <screens.h>
|
||||
#include <display.h>
|
||||
|
||||
#define VERSION "0.1a"
|
||||
static const unsigned long DISPLAY_REFRESH_INTERVAL = 500; // ms
|
||||
static const unsigned long DISPLAY_SCREEN_INTERVAL = 10000; // ms
|
||||
|
||||
//Wifi Setup
|
||||
const char* WIFI_SSID = "IoT_Temp";
|
||||
const char* WIFI_PASS = "FpgtW6LMeZjmTH6J2KoSTTiE7rpEEhtfH8LaCjgFbajH2Bk88fkZFu9CopF96i";
|
||||
//MQTT
|
||||
const char* mqtt_server = "10.1.0.9";
|
||||
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
|
||||
|
||||
//Library setup
|
||||
WiFiManager wifiManager;
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
|
||||
|
@ -220,26 +223,20 @@ void reconnect() {
|
|||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Booting...");
|
||||
display_begin();
|
||||
Serial.println("Display init...");
|
||||
display_init((char*)VERSION);
|
||||
delay(2000);
|
||||
logPrintlnI("Booting solar monitor app..." VERSION);
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
logPrintlnI( "Set WLAN Mode to STA...");
|
||||
WiFi.mode(WIFI_STA);
|
||||
logPrintlnI("Resetting...");
|
||||
WiFi.disconnect();
|
||||
logPrintlnI("Connecting ...");
|
||||
delay(1000);
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.println("Retry connection to WiFi..");
|
||||
display_wifi((char*)"wait");
|
||||
delay(500);
|
||||
client.setServer(mqtt_server, 1883);
|
||||
client.setCallback(callback);
|
||||
}
|
||||
display_wifi((char*)"AP: PV_Mon for Config");
|
||||
wifiManager.addParameter(&custom_mqtt_server);
|
||||
wifiManager.setTimeout(60);
|
||||
wifiManager.autoConnect("PV_Mon");
|
||||
logPrintlnI("Connecting wifi...");
|
||||
IPAddress ip = WiFi.localIP();
|
||||
client.setServer(mqtt_server, 1883);
|
||||
client.setCallback(callback);
|
||||
char* ip_address = new char[40]();
|
||||
sprintf(ip_address, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
display_wifi(ip_address);
|
||||
|
|
|
@ -22,14 +22,9 @@
|
|||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
; THE SOFTWARE.
|
||||
*/
|
||||
//TTGO OLED Screen
|
||||
#define OLED_SDA 21
|
||||
#define OLED_SCL 22
|
||||
#define OLED_RST 16
|
||||
|
||||
//GLCD on ESP8266
|
||||
#define LCD_E_SCLK 14
|
||||
#define LCD_RW_SI 13
|
||||
#define LCD_CS 15
|
||||
|
||||
#define BUTTON_PIN 38
|
||||
#define BUTTON_PIN 6
|
|
@ -1,86 +0,0 @@
|
|||
|
||||
#include "power_management.h"
|
||||
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PowerManagement::PowerManagement() {
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
bool PowerManagement::begin(TwoWire &port) {
|
||||
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
|
||||
if (!result) {
|
||||
axp.setDCDC1Voltage(3300);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::activateLoRa() {
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::deactivateLoRa() {
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::activateGPS() {
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::deactivateGPS() {
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::activateOLED() {
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::decativateOLED() {
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::disableChgLed() {
|
||||
axp.setChgLEDMode(AXP20X_LED_OFF);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::enableChgLed() {
|
||||
axp.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::activateMeasurement() {
|
||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::deactivateMeasurement() {
|
||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, false);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
double PowerManagement::getBatteryVoltage() {
|
||||
return axp.getBattVoltage() / 1000.0;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
double PowerManagement::getBatteryChargeDischargeCurrent() {
|
||||
if (axp.isChargeing()) {
|
||||
return axp.getBattChargeCurrent();
|
||||
}
|
||||
return -1.0 * axp.getBattDischargeCurrent();
|
||||
}
|
||||
|
||||
bool PowerManagement::isBatteryConnect() {
|
||||
return axp.isBatteryConnect();
|
||||
}
|
||||
|
||||
bool PowerManagement::isChargeing() {
|
||||
return axp.isChargeing();
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
#ifndef POWER_MANAGEMENT_H_
|
||||
#define POWER_MANAGEMENT_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <axp20x.h>
|
||||
|
||||
class PowerManagement {
|
||||
public:
|
||||
PowerManagement();
|
||||
bool begin(TwoWire &port);
|
||||
|
||||
void activateLoRa();
|
||||
void deactivateLoRa();
|
||||
|
||||
void activateGPS();
|
||||
void deactivateGPS();
|
||||
|
||||
void activateOLED();
|
||||
void decativateOLED();
|
||||
|
||||
void enableChgLed();
|
||||
void disableChgLed();
|
||||
|
||||
void activateMeasurement();
|
||||
void deactivateMeasurement();
|
||||
|
||||
double getBatteryVoltage();
|
||||
double getBatteryChargeDischargeCurrent();
|
||||
|
||||
bool isBatteryConnect();
|
||||
bool isChargeing();
|
||||
|
||||
private:
|
||||
AXP20X_Class axp;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue