Skip to content

Commit

Permalink
Merge pull request #99 from kike-canaries/ttgo_display
Browse files Browse the repository at this point in the history
TTGO T-Display support
  • Loading branch information
hpsaturn authored Jul 28, 2021
2 parents 1839a85 + f03156f commit 8ee72e2
Show file tree
Hide file tree
Showing 64 changed files with 2,148 additions and 597 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ espota.py
esptool.py
md5output.txt
releases/manifest
releases/installer/rev*

# IDE
.travis.yml
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added box/canairio_bike_sps30/box_SPS30_base.stl
Binary file not shown.
Binary file added box/canairio_bike_sps30/box_SPS30_body.stl
Binary file not shown.
Binary file added box/canairio_bike_sps30/box_SPS30_lid.stl
Binary file not shown.
Binary file not shown.
Binary file added box/canairio_bike_ttgo_display/display_base.stl
Binary file not shown.
Binary file not shown.
Binary file added box/canairio_bike_ttgo_display/display_body.stl
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added box/canairio_bike_ttgo_display/display_lid.stl
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
1 change: 1 addition & 0 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ else
build HELTEC
build TTGO_TQ
build ESP32DEVKIT
build TTGO_TDISPLAY
printOutput
;;

Expand Down
Binary file added docs/panasonic-JA5-SSP-COMM-v10_comm-spec.pdf
Binary file not shown.
Binary file added docs/panasonic-JA5-SSP-v10_product-spec.pdf
Binary file not shown.
Binary file added docs/ttgo_tdisplay.pdf
Binary file not shown.
Binary file added docs/ttgo_tdisplay_pinout.jpg
6 changes: 4 additions & 2 deletions include/bluetooth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include <GUIUtils.hpp>
#include <GUILib.hpp>
#include <Sensors.hpp>
#include <wifi.hpp>

#define SERVICE_UUID "c8d1d262-861f-4082-947e-f383a259aaf3"
#define CHARAC_DATA_UUID "b0f332a8-a5aa-4f3f-bb43-f99e7791ae01"
#define CHARAC_CONFIG_UUID "b0f332a8-a5aa-4f3f-bb43-f99e7791ae02"
#define CHARAC_STATUS_UUID "b0f332a8-a5aa-4f3f-bb43-f99e7791ae03"

void bleLoop();
void bleServerInit();
bool bleIsConnected();
bool bleIsConnected();
void bleServerConfigRefresh();
13 changes: 2 additions & 11 deletions include/wifi.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <WiFi.h>
#include <OTAHandler.h>
#include <esp_wifi.h>
#include <CanAirIoApi.hpp>
#include <InfluxDbClient.h>
#include <ConfigApp.hpp>
#include <InfluxArduino.hpp>
#include <GUIUtils.hpp>
#include <GUILib.hpp>
#include <Watchdog.hpp>
#include <Sensors.hpp>

Expand All @@ -22,13 +21,5 @@ void wifiRestart();
void wifiLoop();
int getWifiRSSI();

bool apiIsConfigured();
void apiInit();
void apiLoop();

bool influxDbIsConfigured();
void influxDbInit();
void influxDbParseFields(char* fields);
void influxDbAddTags(char* tags);
bool influxDbWrite();
void influxDbLoop();
8 changes: 6 additions & 2 deletions lib/canairioota/src/OTAHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,21 @@ void OTAHandler::setup(const char* ESP_ID, const char* ESP_PASS) {

esp32FOTA.checkURL = "http://influxdb.canair.io:8080/releases/" + String(TARGET) + "/firmware_" + String(FLAVOR) + ".json";

Serial.println("-->[INFO] ready for OTA update.");
Serial.println("-->[INFO] OTA ready on: ");
Serial.print("-->[INFO] ");
Serial.print(ESP_ID);
Serial.print(".local with passw: ");
Serial.println(ESP_PASS);
}

void OTAHandler::checkRemoteOTA(bool notify) {
bool updatedNeeded = esp32FOTA.execHTTPcheck();
if (updatedNeeded) {
Serial.println("-->[FOTA] starting upgrade..");
if(_onUpdateMsgCb != nullptr)
_onUpdateMsgCb(String(esp32FOTA.getPayloadVersion()).c_str());
delay(100);
esp_task_wdt_init(120,0);
Serial.println("-->[FOTA] starting..");
esp32FOTA.execOTA();
} else if (notify)
Serial.println("-->[FOTA] not need update");
Expand Down
2 changes: 1 addition & 1 deletion lib/canairioota/src/OTAHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OTAHandler {
public:
OTAHandler();
void setup(const char* ESP_ID, const char* ESP_PASS);
void setCallbacks(OTAHandlerCallbacks* pCallbacks);
void setCallbacks(OTAHandlerCallbacks* pCallBacks);
void setOnUpdateMessageCb(voidMessageCbFn cb);
void loop();
void checkRemoteOTA(bool notify = true);
Expand Down
109 changes: 53 additions & 56 deletions lib/configlib/ConfigApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,10 @@ void ConfigApp::reload() {
ifx.db = preferences.getString("ifxdb", ifx.db);
ifx.ip = preferences.getString("ifxip", ifx.ip);
ifx.pt = preferences.getUInt("ifxpt", ifx.pt);
// canairio api settings
api_enable = preferences.getBool("apiEnable", false);
apiusr = preferences.getString("apiusr", "");
apipss = preferences.getString("apipss", "");
apisrv = preferences.getString("apisrv", "");
apiuri = preferences.getString("apiuri", "");
apiprt = preferences.getInt("apiprt", 80);
// station and sensor settings
lat = preferences.getDouble("lat", 0);
lon = preferences.getDouble("lon", 0);
alt = preferences.getFloat("alt", 0);
spd = preferences.getFloat("spd", 0);
geo = preferences.getString("geo", "");
stime = preferences.getInt("stime", 5);
stype = preferences.getInt("stype", 0);
toffset = preferences.getFloat("toffset", 0.0);
Expand All @@ -59,11 +51,7 @@ String ConfigApp::getCurrentConfig() {
doc["ifxdb"] = preferences.getString("ifxdb", ifx.db); // influxdb database name
doc["ifxip"] = preferences.getString("ifxip", ifx.ip); // influxdb database ip
doc["ifxpt"] = preferences.getUInt("ifxpt", ifx.pt); // influxdb sensor tags
doc["aenb"] = preferences.getBool("apiEnable", false); // CanAirIO API on/off
doc["apiusr"] = preferences.getString("apiusr", ""); // API username
doc["apisrv"] = preferences.getString("apisrv", ""); // API hostname
doc["apiuri"] = preferences.getString("apiuri", ""); // API uri endpoint
doc["apiprt"] = preferences.getInt("apiprt", 80); // API port
doc["geo"] = preferences.getString("geo", ""); // influxdb GeoHash tag
doc["denb"] = preferences.getBool("debugEnable", false); // debug mode enable
doc["i2conly"] = preferences.getBool("i2conly", false); // force only i2c sensors
doc["toffset"] = preferences.getFloat("toffset", 0.0); // temperature offset
Expand Down Expand Up @@ -104,6 +92,13 @@ void ConfigApp::saveInt(String key, int value){
setLastKeySaved(key);
}

int32_t ConfigApp::getInt(String key, int defaultValue){
preferences.begin(_app_name, false);
int32_t out = preferences.getInt(key.c_str(), defaultValue);
preferences.end();
return out;
}

void ConfigApp::saveFloat(String key, float value){
preferences.begin(_app_name, false);
preferences.putFloat(key.c_str(), value);
Expand Down Expand Up @@ -168,7 +163,7 @@ bool ConfigApp::saveWifi(String ssid, String pass){
wifi_enable = true;
isNewWifi = true; // for execute wifi reconnect
Serial.println("-->[CONF] WiFi credentials saved!");
log_i("-->[CONF] ssid:%s pass:%s",ssid,pass);
log_i("[CONF] ssid:%s pass:%s",ssid,pass);
return true;
}
DEBUG("-->[W][CONF] empty Wifi SSID");
Expand All @@ -184,7 +179,6 @@ bool ConfigApp::saveInfluxDb(String db, String ip, int pt) {
preferences.putBool("ifxEnable", true);
preferences.end();
setLastKeySaved("ifxdb");
isNewIfxdbConfig = true;
ifxdb_enable = true;
Serial.printf("-->[CONF] influxdb: %s@%s:%i\n",db.c_str(),ip.c_str(),pt);
Serial.println("-->[CONF] influxdb config saved.");
Expand All @@ -194,38 +188,17 @@ bool ConfigApp::saveInfluxDb(String db, String ip, int pt) {
return false;
}

bool ConfigApp::saveAPI(String usr, String pass, String srv, String uri, int pt){
if (usr.length() > 0 && pass.length() > 0 && srv.length() > 0 && uri.length() > 0) {
preferences.begin(_app_name, false);
preferences.putString("apiusr", usr);
preferences.putString("apipss", pass);
preferences.putString("apisrv", srv);
preferences.putString("apiuri", uri);
if (pt > 0) preferences.putInt("apiprt", pt);
preferences.putBool("apiEnable", true);
preferences.end();
setLastKeySaved("api");
isNewAPIConfig = true;
api_enable = true;
log_i("[CONF] API: %s@%s/%s",usr.c_str(),srv.c_str(),uri.c_str());
Serial.println("-->[CONF] API config saved.");
return true;
}
DEBUG("-->[W][CONF] wrong API params!");
return false;
}

bool ConfigApp::saveGeo(double lat, double lon, float alt, float spd){
bool ConfigApp::saveGeo(double lat, double lon, String geo){
if (lat != 0 && lon != 0) {
preferences.begin(_app_name, false);
preferences.putDouble("lat", lat);
preferences.putDouble("lon", lon);
preferences.putFloat("alt", alt);
preferences.putFloat("spd", spd);
preferences.putString("geo", geo);
preferences.end();
setLastKeySaved("lat");
log_i("-->[CONF] geo:(%d,%d) alt:%d spd:%d",lat,lon,alt,spd);
Serial.println("-->[CONF] updated location!");
log_i("-->[CONF] geo: %s (%d,%d)",geo,lat,lon);
Serial.print("-->[CONF] updated GeoHash to ");
Serial.println(geo);
return true;
}
DEBUG("-->[W][CONF] wrong GEO params!");
Expand All @@ -246,13 +219,6 @@ bool ConfigApp::ifxdbEnable(bool enable) {
return true;
}

bool ConfigApp::apiEnable(bool enable) {
saveBool("apiEnable", enable);
api_enable = enable;
Serial.println("-->[CONF] updating API state: " + String(enable));
return true;
}

bool ConfigApp::debugEnable(bool enable) {
saveBool("debugEnable", enable);
devmode = enable;
Expand Down Expand Up @@ -291,16 +257,14 @@ bool ConfigApp::save(const char *json) {
if (doc.containsKey("stype")) return saveSensorType(doc["stype"] | 0);
if (doc.containsKey("ifxdb")) return saveInfluxDb(doc["ifxdb"] | "", doc["ifxip"] | "", doc["ifxpt"] | 0);
if (doc.containsKey("ssid")) return saveWifi(doc["ssid"] | "", doc["pass"] | "");
if (doc.containsKey("apiusr")) return saveAPI(doc["apiusr"] | "", doc["apipss"] | "", doc["apisrv"] | "", doc["apiuri"] | "", doc["apiprt"] | 0);
if (doc.containsKey("lat")) return saveGeo(doc["lat"].as<double>(), doc["lon"].as<double>(), doc["alt"].as<float>(), doc["spd"].as<float>());
if (doc.containsKey("lat")) return saveGeo(doc["lat"].as<double>(), doc["lon"].as<double>(), doc["geo"] | "");
if (doc.containsKey("toffset")) return saveTempOffset(doc["toffset"].as<float>());


// some actions with chopid validation (for security reasons)
if (cmd == ((uint16_t)(chipid >> 32)) && act.length() > 0) {
if (act.equals("wst")) return wifiEnable(doc["wenb"].as<bool>());
if (act.equals("ist")) return ifxdbEnable(doc["ienb"].as<bool>());
if (act.equals("ast")) return apiEnable(doc["aenb"].as<bool>());
if (act.equals("dst")) return debugEnable(doc["denb"].as<bool>());
if (act.equals("i2c")) return saveI2COnly(doc["i2conly"].as<bool>());
if (act.equals("rbt")) reboot();
Expand All @@ -312,6 +276,24 @@ bool ConfigApp::save(const char *json) {
}
}

bool ConfigApp::getTrackStatusValues(const char *json) {
StaticJsonDocument<200> doc;
auto error = deserializeJson(doc, json);
if (error) {
Serial.print(F("-->[E][CONF] deserialize Json failed with code "));
Serial.println(error.c_str());
return false;
}
if (doc.containsKey("spd")) track.spd = doc["spd"] | 0.0;
if (doc.containsKey("kms")) track.kms = doc["kms"] | 0.0;
if (doc.containsKey("hrs")) track.hrs = doc["hrs"] | 0;
if (doc.containsKey("min")) track.min = doc["min"] | 0;
if (doc.containsKey("seg")) track.seg = doc["seg"] | 0;

return true;
}


String ConfigApp::getDeviceId() {
uint8_t baseMac[6];
// Get MAC address for WiFi station
Expand All @@ -321,12 +303,15 @@ String ConfigApp::getDeviceId() {
return String(baseMacChr);
}

bool ConfigApp::isWifiEnable() {
return wifi_enable;
String ConfigApp::getDeviceIdShort() {
String devId = getDeviceId();
devId = devId.substring(13);
devId.replace(":","");
return devId;
}

bool ConfigApp::isApiEnable() {
return api_enable;
bool ConfigApp::isWifiEnable() {
return wifi_enable;
}

bool ConfigApp::isIfxEnable() {
Expand Down Expand Up @@ -355,6 +340,18 @@ void ConfigApp::reboot() {
ESP.restart();
}

void ConfigApp::saveBrightness(int value){
saveInt("bright",value);
}

int32_t ConfigApp::getBrightness(){
return getInt("bright",30);
}

void ConfigApp::colorsInvertedEnable(bool enable){
saveBool("cinverted",enable);
}

void ConfigApp::DEBUG(const char *text, const char *textb) {
if (devmode) {
_debugPort.print(text);
Expand Down
Loading

0 comments on commit 8ee72e2

Please sign in to comment.