Skip to content

Commit

Permalink
Updated push options
Browse files Browse the repository at this point in the history
  • Loading branch information
mp-se committed Aug 2, 2024
1 parent ed6b5d7 commit 4be5cb1
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 88 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
![release](https://img.shields.io/github/release/mp-se/gravitymon-gateway?label=latest%20release)
![issues](https://img.shields.io/github/issues/mp-se/gravitymon-gateway)
![pr](https://img.shields.io/github/issues-pr/mp-se/gravitymon-gateway)
![dev_build](https://img.shields.io/github/actions/workflow/status/mp-se/gravitymon-blegatewaygw/pio-build.yaml?branch=dev)
![dev_build](https://img.shields.io/github/actions/workflow/status/mp-se/gravitymon-gateway/pio-build.yaml?branch=dev)

# Gravitymon Gateway
# GravityMon Gateway

This project is a test to manage bluetooth data from Gravitymon 2.x version that contain more data than the Tilt protocol.
This is a companion device for use with GravityMon v2.0, it will support the new BLE options and Wifi Direct options introduced into v2.0.

Its designed to run on top of the Tiltbride Hardware where the goal is to incorporate this into that project in the future.
For documentation see www.gravitymon.com.

Its not a replacement for Tiltbridge since this only focus on the GravityMon BLE data formats. The intention is to integrate this feature with Tiltbridge in the future.

There is not yet any documentation for this project.

# About GravityMon
# About GravityMon & GravityMon Gateway

Visit the gravitymon homepage here for more information about the project: https://www.gravitymon.com

Binary file added html/favicon.ico.gz
Binary file not shown.
8 changes: 4 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ build_unflags =
build_flags =
-Wl,-Map,output.map
-D BAUD=${common_env_data.monitor_speed}
#-D USE_LITTLEFS=true
-D CFG_APPVER="\"0.3.0\""
-D CFG_APPVER="\"0.4.0\""
-D CFG_GITREV=\""beta-1\""
#-D ENABLE_REMOTE_UI_DEVELOPMENT
-D ENABLE_REMOTE_UI_DEVELOPMENT
#-D ENABLE_TILT_SCANNING
#!python script/git_rev.py
lib_deps =
Expand All @@ -33,13 +32,14 @@ lib_deps =
https://github.com/mp-se/ESPAsyncWebServer#0.1.1
https://github.com/mp-se/ESPAsyncTCP#0.1.0
https://github.com/mp-se/NimBLE-Arduino#1.4.1
https://github.com/mp-se/espframework#1.0.0
https://github.com/mp-se/espframework#1.0.1
extra_scripts =
script/copy_firmware.py
html_files =
html/index.html
html/app.js.gz
html/app.css.gz
html/favicon.ico.gz

[env:gw-release]
upload_speed = ${common_env_data.upload_speed}
Expand Down
148 changes: 76 additions & 72 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ constexpr auto CFG_AP_PASS = "password";
#endif

void controller();
void displayLog();
void renderDisplay();

// #define FORCE_GRAVITY_MODE
SerialDebug mySerial;
Expand Down Expand Up @@ -194,27 +194,29 @@ void setup() {
myDisplay.printLineCentered(3, "Startup completed");
myDisplay.setFont(FontSize::FONT_9);
delay(1000);
myDisplay.clear();
renderDisplay();
loopMillis = millis();
}

void loop() {
myUptime.calculate();
myWebServer.loop();
myWifi.loop();

switch (runMode) {
case RunMode::gatewayMode:
if (!myWifi.isConnected()) {
Log.warning(F("Loop: Wifi was disconnected, trying to reconnect." CR));
myWifi.connect();
}
controller();
break;

case RunMode::wifiSetupMode:
break;
}

myUptime.calculate();
myWebServer.loop();
myWifi.loop();
controller();
renderDisplay();
}

struct LogEntry {
Expand All @@ -239,82 +241,74 @@ void addLogEntry(const char* id, tm timeinfo, float gravitySG, float tempC) {
}

void controller() {
displayLog();

// Scan for ble beacons
if (runMode == RunMode::gatewayMode) {
bleScanner.scan();
bleScanner.waitForScan();
bleScanner.scan();
bleScanner.waitForScan();

#if defined(ENABLE_TILT_SCANNING)
/*
* This part is for testing / debugging only, use Tiltbridge if you use Tilt
* as BLE transmission, will show detected tilt devices but dont send data.
*/
for (int i = 0; i < NO_TILT_COLORS; i++) {
TiltData td = bleScanner.getTiltData((TiltColor)i);

if (td.updated && (td.getPushAge() > myConfig.getPushResendTime())) {
addLogEntry(bleScanner.getTiltColorAsString((TiltColor)i),
td.timeinfoUpdated, td.gravity, convertFtoC(td.tempF));

Log.notice(F("Main: Type=%s, Gravity=%F, Temp=%F "
"Id=%s." CR),
bleScanner.getTiltColorAsString((TiltColor)i), td.gravity,
convertFtoC(td.tempF));

/*
push.sendAll(td.angle, td.gravity, td.tempC, td.battery, td.interval,
td.id.c_str(), td.token.c_str(), td.name.c_str());
td.setPushed();
*/
}
/*
* This part is for testing / debugging only, use Tiltbridge if you use Tilt
* as BLE transmission, will show detected tilt devices but dont send data.
*/
for (int i = 0; i < NO_TILT_COLORS; i++) {
TiltData td = bleScanner.getTiltData((TiltColor)i);

if (td.updated && (td.getPushAge() > myConfig.getPushResendTime())) {
addLogEntry(bleScanner.getTiltColorAsString((TiltColor)i),
td.timeinfoUpdated, td.gravity, convertFtoC(td.tempF));

Log.notice(F("Main: Type=%s, Gravity=%F, Temp=%F "
"Id=%s." CR),
bleScanner.getTiltColorAsString((TiltColor)i), td.gravity,
convertFtoC(td.tempF));

/*
push.sendAll(td.angle, td.gravity, td.tempC, td.battery, td.interval,
td.id.c_str(), td.token.c_str(), td.name.c_str());
td.setPushed();
*/
}
}
#endif

GravmonGatewayPush push(&myConfig);
GravmonGatewayPush push(&myConfig);

// Process gravitymon from BLE
for (int i = 0; i < NO_GRAVITYMON; i++) {
GravitymonData& gmd = bleScanner.getGravitymonData(i);
// Process gravitymon from BLE
for (int i = 0; i < NO_GRAVITYMON; i++) {
GravitymonData& gmd = bleScanner.getGravitymonData(i);

if (gmd.updated && (gmd.getPushAge() > myConfig.getPushResendTime())) {
addLogEntry(gmd.id.c_str(), gmd.timeinfoUpdated, gmd.gravity,
gmd.tempC);
if (gmd.updated && (gmd.getPushAge() > myConfig.getPushResendTime())) {
addLogEntry(gmd.id.c_str(), gmd.timeinfoUpdated, gmd.gravity, gmd.tempC);

Log.notice(F("Main: Type=%s, Angle=%F Gravity=%F, Temp=%F, Battery=%F, "
"Id=%s." CR),
gmd.type.c_str(), gmd.angle, gmd.gravity, gmd.tempC,
gmd.battery, gmd.id.c_str());
push.sendAll(gmd.angle, gmd.gravity, gmd.tempC, gmd.battery,
gmd.interval, gmd.id.c_str(), gmd.token.c_str(),
gmd.name.c_str());
gmd.setPushed();
}
Log.notice(F("Main: Type=%s, Angle=%F Gravity=%F, Temp=%F, Battery=%F, "
"Id=%s." CR),
gmd.type.c_str(), gmd.angle, gmd.gravity, gmd.tempC,
gmd.battery, gmd.id.c_str());
push.sendAll(gmd.angle, gmd.gravity, gmd.tempC, gmd.battery, gmd.interval,
gmd.id.c_str(), gmd.token.c_str(), gmd.name.c_str());
gmd.setPushed();
}
}

// Process gravitymon from HTTP
for (int i = 0; i < NO_GRAVITYMON; i++) {
GravitymonData& gmd = myWebServer.getGravitymonData(i);

if (gmd.updated && (gmd.getPushAge() > myConfig.getPushResendTime())) {
addLogEntry(gmd.id.c_str(), gmd.timeinfoUpdated, gmd.gravity,
gmd.tempC);

Log.notice(F("Main: Type=%s, Angle=%F Gravity=%F, Temp=%F, Battery=%F, "
"Id=%s." CR),
gmd.type.c_str(), gmd.angle, gmd.gravity, gmd.tempC,
gmd.battery, gmd.id.c_str());
push.sendAll(gmd.angle, gmd.gravity, gmd.tempC, gmd.battery,
gmd.interval, gmd.id.c_str(), gmd.token.c_str(),
gmd.name.c_str());
gmd.setPushed();
}
// Process gravitymon from HTTP
for (int i = 0; i < NO_GRAVITYMON; i++) {
GravitymonData& gmd = myWebServer.getGravitymonData(i);

if (gmd.updated && (gmd.getPushAge() > myConfig.getPushResendTime())) {
addLogEntry(gmd.id.c_str(), gmd.timeinfoUpdated, gmd.gravity, gmd.tempC);

Log.notice(F("Main: Type=%s, Angle=%F Gravity=%F, Temp=%F, Battery=%F, "
"Id=%s." CR),
gmd.type.c_str(), gmd.angle, gmd.gravity, gmd.tempC,
gmd.battery, gmd.id.c_str());
push.sendAll(gmd.angle, gmd.gravity, gmd.tempC, gmd.battery, gmd.interval,
gmd.id.c_str(), gmd.token.c_str(), gmd.name.c_str());
gmd.setPushed();
}
}
}

void displayLog() {
void renderDisplay() {
myDisplay.printLineCentered(0, "GravityMon Gateway");

for (int i = 0, j = logIndex; i < maxLogEntries; i++) {
Expand All @@ -325,11 +319,21 @@ void displayLog() {

char info[80];

if (strlen(myConfig.getWifiDirectSSID())) {
snprintf(&info[0], sizeof(info), "%s - %s",
WiFi.localIP().toString().c_str(), myConfig.getWifiDirectSSID());
} else {
snprintf(&info[0], sizeof(info), "%s", WiFi.localIP().toString().c_str());
switch (runMode) {
case RunMode::gatewayMode:
if (strlen(myConfig.getWifiDirectSSID())) {
snprintf(&info[0], sizeof(info), "%s - %s",
WiFi.localIP().toString().c_str(),
myConfig.getWifiDirectSSID());
} else {
snprintf(&info[0], sizeof(info), "%s",
WiFi.localIP().toString().c_str());
}
break;

case RunMode::wifiSetupMode:
snprintf(&info[0], sizeof(info), "Wifi Setup - 192.168.4.1");
break;
}

myDisplay.printLineCentered(10, &info[0]);
Expand Down
Loading

0 comments on commit 4be5cb1

Please sign in to comment.