Little SIM800L refactor
Signed-off-by: Martin Kolací <martin.kolaci@lmc.eu>
This commit is contained in:
142
Board320_240.cpp
142
Board320_240.cpp
@@ -8,6 +8,8 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "BoardInterface.h"
|
#include "BoardInterface.h"
|
||||||
#include "Board320_240.h"
|
#include "Board320_240.h"
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include "SIM800L.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Init board
|
Init board
|
||||||
@@ -85,6 +87,11 @@ void Board320_240::afterSetup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init SIM800L
|
||||||
|
if (liveData->settings.gprsHwSerialPort <= 2) {
|
||||||
|
sim800lSetup();
|
||||||
|
}
|
||||||
|
|
||||||
// Init from parent class
|
// Init from parent class
|
||||||
Serial.println("BoardInterface::afterSetup");
|
Serial.println("BoardInterface::afterSetup");
|
||||||
BoardInterface::afterSetup();
|
BoardInterface::afterSetup();
|
||||||
@@ -862,7 +869,7 @@ String Board320_240::menuItemCaption(int16_t menuItemId, String title) {
|
|||||||
WL_DISCONNECTED: suffix = "DISCONNECTED"; break;
|
WL_DISCONNECTED: suffix = "DISCONNECTED"; break;
|
||||||
}
|
}
|
||||||
break;*/
|
break;*/
|
||||||
case MENU_GPRS: sprintf(tmpStr1, "[%s] %s", (liveData->settings.gprsEnabled == 1) ? "on" : "off", liveData->settings.gprsApn); suffix = tmpStr1; break;
|
case MENU_GPRS: sprintf(tmpStr1, "[HW UART=%d]", liveData->settings.gprsHwSerialPort); suffix = (liveData->settings.gprsHwSerialPort == 255) ? "[off]" : tmpStr1; break;
|
||||||
case MENU_SDCARD: sprintf(tmpStr1, "[%d] %lluMB", SD.cardType(), SD.cardSize() / (1024 * 1024)); suffix = tmpStr1; break;
|
case MENU_SDCARD: sprintf(tmpStr1, "[%d] %lluMB", SD.cardType(), SD.cardSize() / (1024 * 1024)); suffix = tmpStr1; break;
|
||||||
case MENU_SCREEN_ROTATION: suffix = (liveData->settings.displayRotation == 1) ? "[vertical]" : "[normal]"; break;
|
case MENU_SCREEN_ROTATION: suffix = (liveData->settings.displayRotation == 1) ? "[vertical]" : "[normal]"; break;
|
||||||
case MENU_DEFAULT_SCREEN: sprintf(tmpStr1, "[%d]", liveData->settings.defaultScreen); suffix = tmpStr1; break;
|
case MENU_DEFAULT_SCREEN: sprintf(tmpStr1, "[%d]", liveData->settings.defaultScreen); suffix = tmpStr1; break;
|
||||||
@@ -1024,6 +1031,7 @@ void Board320_240::menuItemClick() {
|
|||||||
// Pre-drawn charg.graphs off/on
|
// Pre-drawn charg.graphs off/on
|
||||||
case MENU_PREDRAWN_GRAPHS: liveData->settings.predrawnChargingGraphs = (liveData->settings.predrawnChargingGraphs == 1) ? 0 : 1; showMenu(); return; break;
|
case MENU_PREDRAWN_GRAPHS: liveData->settings.predrawnChargingGraphs = (liveData->settings.predrawnChargingGraphs == 1) ? 0 : 1; showMenu(); return; break;
|
||||||
case MENU_HEADLIGHTS_REMINDER: liveData->settings.headlightsReminder = (liveData->settings.headlightsReminder == 1) ? 0 : 1; showMenu(); return; break;
|
case MENU_HEADLIGHTS_REMINDER: liveData->settings.headlightsReminder = (liveData->settings.headlightsReminder == 1) ? 0 : 1; showMenu(); return; break;
|
||||||
|
case MENU_GPRS: liveData->settings.gprsHwSerialPort = (liveData->settings.gprsHwSerialPort == 2) ? 255 : liveData->settings.gprsHwSerialPort + 1; showMenu(); return; break;
|
||||||
case MENU_GPS: liveData->settings.gpsHwSerialPort = (liveData->settings.gpsHwSerialPort == 2) ? 255 : liveData->settings.gpsHwSerialPort + 1; showMenu(); return; break;
|
case MENU_GPS: liveData->settings.gpsHwSerialPort = (liveData->settings.gpsHwSerialPort == 2) ? 255 : liveData->settings.gpsHwSerialPort + 1; showMenu(); return; break;
|
||||||
// Wifi menu
|
// Wifi menu
|
||||||
case MENU_WIFI_ENABLED: liveData->settings.wifiEnabled = (liveData->settings.wifiEnabled == 1) ? 0 : 1; showMenu(); return; break;
|
case MENU_WIFI_ENABLED: liveData->settings.wifiEnabled = (liveData->settings.wifiEnabled == 1) ? 0 : 1; showMenu(); return; break;
|
||||||
@@ -1282,6 +1290,12 @@ void Board320_240::mainLoop() {
|
|||||||
syncGPS();
|
syncGPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SIM800L
|
||||||
|
if (liveData->params.lastDataSent + SIM800L_TIMER < liveData->params.currentTime && liveData->params.sim800l_enabled) {
|
||||||
|
sendDataViaGPRS();
|
||||||
|
liveData->params.lastDataSent = liveData->params.currentTime;
|
||||||
|
}
|
||||||
|
|
||||||
// currentTime
|
// currentTime
|
||||||
struct tm now;
|
struct tm now;
|
||||||
getLocalTime(&now, 0);
|
getLocalTime(&now, 0);
|
||||||
@@ -1330,7 +1344,7 @@ void Board320_240::mainLoop() {
|
|||||||
shutdownDevice();
|
shutdownDevice();
|
||||||
|
|
||||||
// Read data from BLE/CAN
|
// Read data from BLE/CAN
|
||||||
commInterface->mainLoop();
|
commInterface->mainLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1454,3 +1468,127 @@ void Board320_240::syncGPS() {
|
|||||||
settimeofday(&now, NULL);
|
settimeofday(&now, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
SIM800L
|
||||||
|
*/
|
||||||
|
bool Board320_240::sim800lSetup() {
|
||||||
|
Serial.print("Setting SIM800L module. HW port: ");
|
||||||
|
Serial.println(liveData->settings.gprsHwSerialPort);
|
||||||
|
|
||||||
|
gprsHwUart = new HardwareSerial(liveData->settings.gprsHwSerialPort);
|
||||||
|
gprsHwUart->begin(9600);
|
||||||
|
|
||||||
|
sim800l = new SIM800L((Stream *)gprsHwUart, SIM800L_RST, 512 , 512);
|
||||||
|
// SIM800L DebugMode:
|
||||||
|
//sim800l = new SIM800L((Stream *)gprsHwUart, SIM800L_RST, 512 , 512, (Stream *)&Serial);
|
||||||
|
|
||||||
|
bool sim800l_ready = sim800l->isReady();
|
||||||
|
for (uint8_t i = 0; i < 5 && !sim800l_ready; i++) {
|
||||||
|
Serial.println("Problem to initialize SIM800L module, retry in 1 sec");
|
||||||
|
delay(1000);
|
||||||
|
sim800l_ready = sim800l->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sim800l_ready) {
|
||||||
|
Serial.println("Problem to initialize SIM800L module");
|
||||||
|
} else {
|
||||||
|
Serial.println("SIM800L module initialized");
|
||||||
|
|
||||||
|
Serial.print("Setting GPRS APN to: ");
|
||||||
|
Serial.println(liveData->settings.gprsApn);
|
||||||
|
|
||||||
|
bool sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn);
|
||||||
|
for (uint8_t i = 0; i < 5 && !sim800l_gprs; i++) {
|
||||||
|
Serial.println("Problem to set GPRS APN, retry in 1 sec");
|
||||||
|
delay(1000);
|
||||||
|
sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sim800l_gprs) {
|
||||||
|
liveData->params.sim800l_enabled = true;
|
||||||
|
Serial.println("GPRS APN set OK");
|
||||||
|
} else {
|
||||||
|
Serial.println("Problem to set GPRS APN");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Board320_240::sendDataViaGPRS() {
|
||||||
|
Serial.println("Sending data via GPRS");
|
||||||
|
|
||||||
|
if (liveData->params.socPerc < 0) {
|
||||||
|
Serial.println("No valid data, skipping data send");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkRegistration network = sim800l->getRegistrationStatus();
|
||||||
|
if (network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
|
||||||
|
Serial.println("SIM800L module not connected to network, skipping data send");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sim800l->isConnectedGPRS()) {
|
||||||
|
Serial.println("GPRS not connected... Connecting");
|
||||||
|
bool connected = sim800l->connectGPRS();
|
||||||
|
for (uint8_t i = 0; i < 5 && !connected; i++) {
|
||||||
|
Serial.println("Problem to connect GPRS, retry in 1 sec");
|
||||||
|
delay(1000);
|
||||||
|
connected = sim800l->connectGPRS();
|
||||||
|
}
|
||||||
|
if (connected) {
|
||||||
|
Serial.println("GPRS connected!");
|
||||||
|
} else {
|
||||||
|
Serial.println("GPRS not connected! Reseting SIM800L module!");
|
||||||
|
sim800l->reset();
|
||||||
|
sim800lSetup();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("Start HTTP POST...");
|
||||||
|
|
||||||
|
StaticJsonDocument<512> jsonData;
|
||||||
|
|
||||||
|
jsonData["apikey"] = liveData->settings.remoteApiKey;
|
||||||
|
jsonData["carType"] = liveData->settings.carType;
|
||||||
|
jsonData["socPerc"] = liveData->params.socPerc;
|
||||||
|
jsonData["sohPerc"] = liveData->params.sohPerc;
|
||||||
|
jsonData["batPowerKw"] = liveData->params.batPowerKw;
|
||||||
|
jsonData["batPowerAmp"] = liveData->params.batPowerAmp;
|
||||||
|
jsonData["batVoltage"] = liveData->params.batVoltage;
|
||||||
|
jsonData["auxVoltage"] = liveData->params.auxVoltage;
|
||||||
|
jsonData["auxAmp"] = liveData->params.auxCurrentAmp;
|
||||||
|
jsonData["batMinC"] = liveData->params.batMinC;
|
||||||
|
jsonData["batMaxC"] = liveData->params.batMaxC;
|
||||||
|
jsonData["batInletC"] = liveData->params.batInletC;
|
||||||
|
jsonData["batFanStatus"] = liveData->params.batFanStatus;
|
||||||
|
jsonData["speedKmh"] = liveData->params.speedKmh;
|
||||||
|
jsonData["odoKm"] = liveData->params.odoKm;
|
||||||
|
jsonData["cumulativeEnergyChargedKWh"] = liveData->params.cumulativeEnergyChargedKWh;
|
||||||
|
jsonData["cumulativeEnergyDischargedKWh"] = liveData->params.cumulativeEnergyDischargedKWh;
|
||||||
|
|
||||||
|
char payload[512];
|
||||||
|
serializeJson(jsonData, payload);
|
||||||
|
|
||||||
|
Serial.print("Sending payload: ");
|
||||||
|
Serial.println(payload);
|
||||||
|
|
||||||
|
Serial.print("Remote API server: ");
|
||||||
|
Serial.println(liveData->settings.remoteApiUrl);
|
||||||
|
|
||||||
|
uint16_t rc = sim800l->doPost(liveData->settings.remoteApiUrl, "application/json", payload, 10000, 10000);
|
||||||
|
if (rc == 200) {
|
||||||
|
Serial.println("HTTP POST successful");
|
||||||
|
} else {
|
||||||
|
// Failed...
|
||||||
|
Serial.print("HTTP POST error: ");
|
||||||
|
Serial.println(rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "BoardInterface.h"
|
#include "BoardInterface.h"
|
||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
#include "SIM800L.h"
|
||||||
|
|
||||||
class Board320_240 : public BoardInterface {
|
class Board320_240 : public BoardInterface {
|
||||||
|
|
||||||
@@ -25,6 +26,8 @@ class Board320_240 : public BoardInterface {
|
|||||||
TFT_eSPI tft = TFT_eSPI();
|
TFT_eSPI tft = TFT_eSPI();
|
||||||
TFT_eSprite spr = TFT_eSprite(&tft);
|
TFT_eSprite spr = TFT_eSprite(&tft);
|
||||||
HardwareSerial* gpsHwUart = NULL;
|
HardwareSerial* gpsHwUart = NULL;
|
||||||
|
HardwareSerial* gprsHwUart = NULL;
|
||||||
|
SIM800L* sim800l;
|
||||||
TinyGPSPlus gps;
|
TinyGPSPlus gps;
|
||||||
char tmpStr1[20];
|
char tmpStr1[20];
|
||||||
char tmpStr2[20];
|
char tmpStr2[20];
|
||||||
@@ -51,6 +54,9 @@ class Board320_240 : public BoardInterface {
|
|||||||
void sdcardToggleRecording() override;
|
void sdcardToggleRecording() override;
|
||||||
// GPS
|
// GPS
|
||||||
void syncGPS();
|
void syncGPS();
|
||||||
|
// SIM800L
|
||||||
|
bool sim800lSetup();
|
||||||
|
bool sendDataViaGPRS();
|
||||||
// Basic GUI
|
// Basic GUI
|
||||||
void setBrightness(byte lcdBrightnessPerc) override;
|
void setBrightness(byte lcdBrightnessPerc) override;
|
||||||
void displayMessage(const char* row1, const char* row2) override;
|
void displayMessage(const char* row1, const char* row2) override;
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ void BoardInterface::loadSettings() {
|
|||||||
tmpStr.toCharArray(liveData->settings.remoteApiKey, tmpStr.length() + 1);
|
tmpStr.toCharArray(liveData->settings.remoteApiKey, tmpStr.length() + 1);
|
||||||
liveData->settings.headlightsReminder = 0;
|
liveData->settings.headlightsReminder = 0;
|
||||||
liveData->settings.gpsHwSerialPort = 255; // off
|
liveData->settings.gpsHwSerialPort = 255; // off
|
||||||
|
liveData->settings.gprsHwSerialPort = 255; // off
|
||||||
|
|
||||||
// Load settings and replace default values
|
// Load settings and replace default values
|
||||||
Serial.println("Reading settings from eeprom.");
|
Serial.println("Reading settings from eeprom.");
|
||||||
|
|||||||
@@ -188,6 +188,7 @@ typedef struct {
|
|||||||
// === settings version 5
|
// === settings version 5
|
||||||
// =================================
|
// =================================
|
||||||
byte gpsHwSerialPort; // 255-off, 0,1,2 - hw serial
|
byte gpsHwSerialPort; // 255-off, 0,1,2 - hw serial
|
||||||
|
byte gprsHwSerialPort; // 255-off, 0,1,2 - hw serial
|
||||||
//
|
//
|
||||||
} SETTINGS_STRUC;
|
} SETTINGS_STRUC;
|
||||||
|
|
||||||
@@ -239,4 +240,3 @@ class LiveData {
|
|||||||
float celsius2temperature(float inCelsius);
|
float celsius2temperature(float inCelsius);
|
||||||
float bar2pressure(float inBar);
|
float bar2pressure(float inBar);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
6
config.h
6
config.h
@@ -47,13 +47,8 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// SIM800L
|
// SIM800L
|
||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifdef SIM800L_ENABLED
|
|
||||||
#define SIM800L_RX 16
|
|
||||||
#define SIM800L_TX 17
|
|
||||||
#define SIM800L_RST 5
|
#define SIM800L_RST 5
|
||||||
#define SIM800L_TIMER 60
|
#define SIM800L_TIMER 60
|
||||||
#endif //SIM800L_ENABLED
|
|
||||||
|
|
||||||
// MENU ITEM
|
// MENU ITEM
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -100,4 +95,3 @@ typedef struct {
|
|||||||
#define MENU_SDCARD_MOUNT_STATUS 3043
|
#define MENU_SDCARD_MOUNT_STATUS 3043
|
||||||
#define MENU_SDCARD_REC 3044
|
#define MENU_SDCARD_REC 3044
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|||||||
145
evDash.ino
145
evDash.ino
@@ -30,8 +30,6 @@
|
|||||||
//#define BOARD_TTGO_T4
|
//#define BOARD_TTGO_T4
|
||||||
#define BOARD_M5STACK_CORE
|
#define BOARD_M5STACK_CORE
|
||||||
|
|
||||||
//#define SIM800L_ENABLED
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -55,142 +53,11 @@
|
|||||||
#include "CarKiaDebugObd2.h"
|
#include "CarKiaDebugObd2.h"
|
||||||
#include "CarBmwI3.h"
|
#include "CarBmwI3.h"
|
||||||
|
|
||||||
#ifdef SIM800L_ENABLED
|
|
||||||
#include <ArduinoJson.h>
|
|
||||||
#include "SIM800L.h"
|
|
||||||
|
|
||||||
SIM800L* sim800l;
|
|
||||||
HardwareSerial SerialGPRS(2);
|
|
||||||
#endif //SIM800L_ENABLED
|
|
||||||
|
|
||||||
// Board, Car, Livedata (params, settings)
|
// Board, Car, Livedata (params, settings)
|
||||||
BoardInterface* board;
|
BoardInterface* board;
|
||||||
CarInterface* car;
|
CarInterface* car;
|
||||||
LiveData* liveData;
|
LiveData* liveData;
|
||||||
|
|
||||||
/**
|
|
||||||
SIM800L
|
|
||||||
*/
|
|
||||||
#ifdef SIM800L_ENABLED
|
|
||||||
bool sim800lSetup() {
|
|
||||||
Serial.println("Setting SIM800L module");
|
|
||||||
|
|
||||||
SerialGPRS.begin(9600);
|
|
||||||
|
|
||||||
sim800l = new SIM800L((Stream *)&SerialGPRS, SIM800L_RST, 512 , 512);
|
|
||||||
// SIM800L DebugMode:
|
|
||||||
//sim800l = new SIM800L((Stream *)&SerialGPRS, SIM800L_RST, 512 , 512, (Stream *)&Serial);
|
|
||||||
|
|
||||||
bool sim800l_ready = sim800l->isReady();
|
|
||||||
for (uint8_t i = 0; i < 5 && !sim800l_ready; i++) {
|
|
||||||
Serial.println("Problem to initialize SIM800L module, retry in 1 sec");
|
|
||||||
delay(1000);
|
|
||||||
sim800l_ready = sim800l->isReady();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sim800l_ready) {
|
|
||||||
Serial.println("Problem to initialize SIM800L module");
|
|
||||||
} else {
|
|
||||||
Serial.println("SIM800L module initialized");
|
|
||||||
|
|
||||||
Serial.print("Setting GPRS APN to: ");
|
|
||||||
Serial.println(liveData->settings.gprsApn);
|
|
||||||
|
|
||||||
bool sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn);
|
|
||||||
for (uint8_t i = 0; i < 5 && !sim800l_gprs; i++) {
|
|
||||||
Serial.println("Problem to set GPRS APN, retry in 1 sec");
|
|
||||||
delay(1000);
|
|
||||||
sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sim800l_gprs) {
|
|
||||||
liveData->params.sim800l_enabled = true;
|
|
||||||
Serial.println("GPRS APN set OK");
|
|
||||||
} else {
|
|
||||||
Serial.println("Problem to set GPRS APN");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendDataViaGPRS() {
|
|
||||||
Serial.println("Sending data via GPRS");
|
|
||||||
|
|
||||||
if (liveData->params.socPerc < 0) {
|
|
||||||
Serial.println("No valid data, skipping data send");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkRegistration network = sim800l->getRegistrationStatus();
|
|
||||||
if (network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
|
|
||||||
Serial.println("SIM800L module not connected to network, skipping data send");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sim800l->isConnectedGPRS()) {
|
|
||||||
Serial.println("GPRS not connected... Connecting");
|
|
||||||
bool connected = sim800l->connectGPRS();
|
|
||||||
for (uint8_t i = 0; i < 5 && !connected; i++) {
|
|
||||||
Serial.println("Problem to connect GPRS, retry in 1 sec");
|
|
||||||
delay(1000);
|
|
||||||
connected = sim800l->connectGPRS();
|
|
||||||
}
|
|
||||||
if (connected) {
|
|
||||||
Serial.println("GPRS connected!");
|
|
||||||
} else {
|
|
||||||
Serial.println("GPRS not connected! Reseting SIM800L module!");
|
|
||||||
sim800l->reset();
|
|
||||||
sim800lSetup();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println("Start HTTP POST...");
|
|
||||||
|
|
||||||
StaticJsonDocument<512> jsonData;
|
|
||||||
|
|
||||||
jsonData["apikey"] = liveData->settings.remoteApiKey;
|
|
||||||
jsonData["carType"] = liveData->settings.carType;
|
|
||||||
jsonData["socPerc"] = liveData->params.socPerc;
|
|
||||||
jsonData["sohPerc"] = liveData->params.sohPerc;
|
|
||||||
jsonData["batPowerKw"] = liveData->params.batPowerKw;
|
|
||||||
jsonData["batPowerAmp"] = liveData->params.batPowerAmp;
|
|
||||||
jsonData["batVoltage"] = liveData->params.batVoltage;
|
|
||||||
jsonData["auxVoltage"] = liveData->params.auxVoltage;
|
|
||||||
jsonData["auxAmp"] = liveData->params.auxCurrentAmp;
|
|
||||||
jsonData["batMinC"] = liveData->params.batMinC;
|
|
||||||
jsonData["batMaxC"] = liveData->params.batMaxC;
|
|
||||||
jsonData["batInletC"] = liveData->params.batInletC;
|
|
||||||
jsonData["batFanStatus"] = liveData->params.batFanStatus;
|
|
||||||
jsonData["speedKmh"] = liveData->params.speedKmh;
|
|
||||||
jsonData["odoKm"] = liveData->params.odoKm;
|
|
||||||
jsonData["cumulativeEnergyChargedKWh"] = liveData->params.cumulativeEnergyChargedKWh;
|
|
||||||
jsonData["cumulativeEnergyDischargedKWh"] = liveData->params.cumulativeEnergyDischargedKWh;
|
|
||||||
|
|
||||||
char payload[512];
|
|
||||||
serializeJson(jsonData, payload);
|
|
||||||
|
|
||||||
Serial.print("Sending payload: ");
|
|
||||||
Serial.println(payload);
|
|
||||||
|
|
||||||
Serial.print("Remote API server: ");
|
|
||||||
Serial.println(liveData->settings.remoteApiUrl);
|
|
||||||
|
|
||||||
uint16_t rc = sim800l->doPost(liveData->settings.remoteApiUrl, "application/json", payload, 10000, 10000);
|
|
||||||
if (rc == 200) {
|
|
||||||
Serial.println("HTTP POST successful");
|
|
||||||
} else {
|
|
||||||
// Failed...
|
|
||||||
Serial.print("HTTP POST error: ");
|
|
||||||
Serial.println(rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif //SIM800L_ENABLED
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Setup device
|
Setup device
|
||||||
*/
|
*/
|
||||||
@@ -247,10 +114,6 @@ void setup(void) {
|
|||||||
// Redraw screen
|
// Redraw screen
|
||||||
board->redrawScreen();
|
board->redrawScreen();
|
||||||
|
|
||||||
#ifdef SIM800L_ENABLED
|
|
||||||
sim800lSetup();
|
|
||||||
#endif //SIM800L_ENABLED
|
|
||||||
|
|
||||||
// Finish board setup
|
// Finish board setup
|
||||||
board->afterSetup();
|
board->afterSetup();
|
||||||
|
|
||||||
@@ -262,13 +125,5 @@ void setup(void) {
|
|||||||
Main loop
|
Main loop
|
||||||
*/
|
*/
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
#ifdef SIM800L_ENABLED
|
|
||||||
if (liveData->params.lastDataSent + SIM800L_TIMER < liveData->params.currentTime && liveData->params.sim800l_enabled) {
|
|
||||||
sendDataViaGPRS();
|
|
||||||
liveData->params.lastDataSent = liveData->params.currentTime;
|
|
||||||
}
|
|
||||||
#endif // SIM800L_ENABLED
|
|
||||||
|
|
||||||
board->mainLoop();
|
board->mainLoop();
|
||||||
}
|
}
|
||||||
|
|||||||
2
menu.h
2
menu.h
@@ -35,7 +35,7 @@ MENU_ITEM menuItemsSource[100] = {
|
|||||||
// {MENU_WIFI, 3, -1, "[dev] WiFi network"},
|
// {MENU_WIFI, 3, -1, "[dev] WiFi network"},
|
||||||
{MENU_SDCARD, 3, -1, "SD card"},
|
{MENU_SDCARD, 3, -1, "SD card"},
|
||||||
{MENU_GPS, 3, -1, "GPS"},
|
{MENU_GPS, 3, -1, "GPS"},
|
||||||
{MENU_GPRS, 3, -1, "[dev] GSM/GPRS"},
|
{MENU_GPRS, 3, -1, "GSM/GPRS"},
|
||||||
//{MENU_REMOTE_UPLOAD, 3, -1, "[dev] Remote upload"},
|
//{MENU_REMOTE_UPLOAD, 3, -1, "[dev] Remote upload"},
|
||||||
//{MENU_NTP, 3, -1, "[dev] NTP"},
|
//{MENU_NTP, 3, -1, "[dev] NTP"},
|
||||||
{MENU_SCREEN_ROTATION, 3, -1, "Screen rotation"},
|
{MENU_SCREEN_ROTATION, 3, -1, "Screen rotation"},
|
||||||
|
|||||||
Reference in New Issue
Block a user