Browse Source

insert defines and worked in setup page + convert.py

pull/345/head
DanielR92 3 years ago
parent
commit
609257d65f
  1. 5
      tools/esp8266/app.cpp
  2. 8
      tools/esp8266/defines.h
  3. 24
      tools/esp8266/html/convert.py
  4. 24
      tools/esp8266/html/setup.html
  5. 2
      tools/esp8266/platformio.ini
  6. 7
      tools/esp8266/web.cpp
  7. 8
      tools/esp8266/webApi.cpp
  8. 1
      tools/esp8266/webApi.h

5
tools/esp8266/app.cpp

@ -745,6 +745,11 @@ void app::loadDefaultConfig(void) {
snprintf(mConfig.ntpAddr, NTP_ADDR_LEN, "%s", DEF_NTP_SERVER_NAME);
mConfig.ntpPort = DEF_NTP_PORT;
// Latitude + Longitude
mConfig.lat = 0;
mConfig.lon = 0;
mConfig.disnightcom = false; // disable night communication
// mqtt
snprintf(mConfig.mqtt.broker, MQTT_ADDR_LEN, "%s", DEF_MQTT_BROKER);
mConfig.mqtt.port = DEF_MQTT_PORT;

8
tools/esp8266/defines.h

@ -82,7 +82,6 @@ typedef enum {
#define INV_CH_CH_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH * 4 // (4 channels)
#define INV_INTERVAL_LEN 2 // uint16_t
#define INV_MAX_RTRY_LEN 1 // uint8_t
#define INV_PWR_LIM_LEN MAX_NUM_INVERTERS * 2 // uint16_t
#define NTP_ADDR_LEN 32 // DNS Name
@ -132,6 +131,11 @@ typedef struct {
// mqtt
mqttConfig_t mqtt;
// Latitude + Longitude
float lat;
float lon;
bool disnightcom;
// serial
uint16_t serialInterval;
bool serialShowIv;
@ -149,7 +153,7 @@ typedef struct {
#define CFG_MQTT_LEN MQTT_ADDR_LEN + 2 + MQTT_USER_LEN + MQTT_PWD_LEN +MQTT_TOPIC_LEN
#define CFG_SYS_LEN DEVNAME_LEN + SSID_LEN + PWD_LEN + 1
#define CFG_LEN 7 + NTP_ADDR_LEN + 2 + CFG_MQTT_LEN + 4
#define CFG_LEN 7 + NTP_ADDR_LEN + 2 + CFG_MQTT_LEN + (4 + 4 + 1) + 4 // in the brackets its needed for lon+lat+bool
#define ADDR_START 0
#define ADDR_CFG_SYS ADDR_START

24
tools/esp8266/html/convert.py

@ -1,6 +1,7 @@
import re
import os
import gzip
import glob
from pathlib import Path
@ -62,10 +63,19 @@ def convert2Header(inFile, compress):
f.write("#endif /*__{}_{}_H__*/\n".format(define, define2))
f.close()
convert2Header("index.html", True)
convert2Header("setup.html", True)
convert2Header("visualization.html", True)
convert2Header("update.html", True)
convert2Header("serial.html", True)
convert2Header("style.css", True)
convert2Header("api.js", True)
# Todo: delete all, but ignore 'favicon_ico_gz.h'
# delete all files in the 'h' dir
#dir = './html/h'
#for f in os.listdir(dir):
# os.remove(os.path.join(dir, f))
# grab all files with following extensions
os.chdir('./html')
types = ('*.html', '*.css', '*.js') # the tuple of file types
files_grabbed = []
for files in types:
files_grabbed.extend(glob.glob(files))
# go throw the array
for val in files_grabbed:
convert2Header(val, True)

24
tools/esp8266/html/setup.html

@ -71,6 +71,23 @@
</fieldset>
</div>
<button type="button" class="s_collapsible">Sunrise & Sunset</button>
<div class="s_content">
<fieldset>
<legend class="des">Sunrise & Sunset</legend>
<input id="clickMe" type="button" value="Get Location from Browser" onclick="getLocation();" /> Info: work only in SSL.
<p id="demo"></p>
<br>
<label for="lat">Latitude</label>
<input type="text" class="text" name="lat"/>
<label for="lon">Longitude</label>
<input type="text" class="text" name="lon"/>
<br>
<label for="disnightcom">disable night communication</label>
<input type="checkbox" class="cb" name="disnightcom"/><br/>
</fieldset>
</div>
<button type="button" class="s_collapsible">MQTT</button>
<div class="s_content">
<fieldset>
@ -237,6 +254,12 @@
document.getElementsByName(i[0])[0].value = obj[i[1]];
}
function parseLatLong(obj) {
for(var i of [["lat", "Latitude"], ["lon", "Longitude"]])
document.getElementsByName(i[0])[0].value = obj[i[1]];
document.getElementById("disnightcom").innerHTML = obj["obj"]
}
function parsePinout(obj) {
var e = document.getElementById("pinout");
pins = [['cs', 'pinCs'], ['ce', 'pinCe'], ['irq', 'pinIrq']];
@ -287,6 +310,7 @@
parseIv(root["inverter"]);
parseMqtt(root["mqtt"]);
parseNtp(root["ntp"]);
parseLatLong(root["LatiLong"]);
parsePinout(root["pinout"]);
parseRadio(root["radio"]);
parseSerial(root["serial"]);

2
tools/esp8266/platformio.ini

@ -28,8 +28,8 @@ build_flags =
monitor_speed = 115200
extra_scripts =
pre:scripts/auto_firmware_version.py
pre:html/convert.py
pre:scripts/auto_firmware_version.py
lib_deps =
https://github.com/yubox-node-org/ESPAsyncWebServer

7
tools/esp8266/web.cpp

@ -272,6 +272,13 @@ void web::showSave(AsyncWebServerRequest *request) {
mConfig->ntpPort = request->arg("ntpPort").toInt() & 0xffff;
}
// Latitude + Longitude
if(request->arg("lon") != "") {
mConfig->lat = request->arg("lat").toFloat();
mConfig->lon = request->arg("lon").toFloat();
mConfig->disnightcom = (request->arg("disnightcom") == "on");
}
// mqtt
if(request->arg("mqttAddr") != "") {
String addr = request->arg("mqttAddr");

8
tools/esp8266/webApi.cpp

@ -185,6 +185,13 @@ void webApi::getNtp(JsonObject obj) {
obj[F("port")] = String(mConfig->ntpPort);
}
//-----------------------------------------------------------------------------
void webApi::getLatiLong(JsonObject obj) {
obj[F("lat")] = mConfig->lat;
obj[F("lon")] = mConfig->lon;
obj[F("disnightcom")] = mConfig->disnightcom;
}
//-----------------------------------------------------------------------------
void webApi::getPinout(JsonObject obj) {
@ -252,6 +259,7 @@ void webApi::getSetup(JsonObject obj) {
getInverterList(obj.createNestedObject(F("inverter")));
getMqtt(obj.createNestedObject(F("mqtt")));
getNtp(obj.createNestedObject(F("ntp")));
getLatiLong(obj.createNestedObject(F("LatiLong")));
getPinout(obj.createNestedObject(F("pinout")));
getRadio(obj.createNestedObject(F("radio")));
getSerial(obj.createNestedObject(F("serial")));

1
tools/esp8266/webApi.h

@ -32,6 +32,7 @@ class webApi {
void getInverterList(JsonObject obj);
void getMqtt(JsonObject obj);
void getNtp(JsonObject obj);
void getLatiLong(JsonObject obj);
void getPinout(JsonObject obj);
void getRadio(JsonObject obj);
void getSerial(JsonObject obj);

Loading…
Cancel
Save