Skip to content

Commit

Permalink
Merge pull request #129 from maxbundscherer/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
maxbundscherer authored Sep 12, 2022
2 parents 5915004 + 3d22ba3 commit c006823
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 9 deletions.
3 changes: 3 additions & 0 deletions independer-app/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ lib_deps =
boseji/rBase64@^1.1.1
boseji/xxtea-iot-crypt@^2.0.1
bblanchon/ArduinoJson@^6.19.4
arduino-libraries/NTPClient@^3.2.1
gyverlibs/UnixTime@^1.1
fbiego/ESP32Time@^2.0.0
; monitor_filters = esp32_exception_decoder
; build_type = debug

Expand Down
8 changes: 5 additions & 3 deletions independer-app/src/device/mb-gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,11 @@ S_GUI_INPUT_TEXT gui_input_text(String menu_title, String default_value)
return S_GUI_INPUT_TEXT{true, current};
}

char gui_input_char_no_output()
char gui_input_char_no_output(boolean displayOffFlag)
{

display.displayOff();
if (displayOffFlag)
display.displayOff();

i_gui_flush_input();

Expand All @@ -886,7 +887,8 @@ char gui_input_char_no_output()
}
}

display.displayOn();
if (displayOffFlag)
display.displayOn();
return ret_char;
}

Expand Down
68 changes: 68 additions & 0 deletions independer-app/src/device/mb-time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <WiFi.h>
#include <NTPClient.h>
#include <UnixTime.h>
#include <ESP32Time.h>

WiFiUDP ntpUDP;

// By default 'pool.ntp.org' is used with 60 seconds update interval and
// no offset
NTPClient timeClient(ntpUDP);

UnixTime stamp(2); // UTC+2
ESP32Time rtc(0); // Offset is already in stamp (else 3600 * 2)

String i_time_convert_current_time_to_string()
{
stamp.getDateTime(rtc.getEpoch());
return String(stamp.year) + "-" + String(stamp.month) + "-" + String(stamp.day) + " " + String(stamp.hour) + ":" + String(stamp.minute) + ":" + String(stamp.second);
}

String time_sync_get_ntp()
{

String ret = "";

Serial.println("(Sync NTP now)");

// Connect to Wi-Fi
char *char_array_ssid = const_cast<char *>(state_wifi_ssid.c_str());
char *char_array_pw = const_cast<char *>(state_wifi_pw.c_str());

WiFi.begin(char_array_ssid, char_array_pw);
Serial.println("WiFi connection ");
int failCounter = 20;
while (WiFi.status() != WL_CONNECTED and failCounter > 0)
{
delay(500);
Serial.print(".");
failCounter--;
}
Serial.println("");
Serial.println("WiFi connected.");

timeClient.begin();
timeClient.update();
rtc.setTime(timeClient.getEpochTime());
// rtc.offset = 3600 * 2; //Offset is already in stamp
ret = i_time_convert_current_time_to_string();
timeClient.end();

// disconnect WiFi as it's no longer needed
WiFi.disconnect(true);

return ret;
}

String time_get_from_local()
{

String ret = i_time_convert_current_time_to_string();

return ret;
}

void time_debug_console_output()
{
Serial.println("Current Time: '" + i_time_convert_current_time_to_string() + "'");
}
8 changes: 4 additions & 4 deletions independer-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ boolean c_actor_mode = false;
* ####################################
*/
// Product Config
String c_product_version = "v.0.3.4";
boolean c_demo_mode = false;
String c_product_version = "v.0.3.5";

/*
* ####################################
Expand Down Expand Up @@ -66,6 +65,9 @@ String state_wifi_server_device_token = ""; // saved in db and INIT CO
// Database
#include "device/mb-database.h"

// Time
#include "device/mb-time.h"

// OTA
#include "device/mb-ota.h"

Expand Down Expand Up @@ -93,8 +95,6 @@ void setup()
{ // Show every boot on gateway
gui_logo_static(c_product_version, state_my_id, state_gateway_id, c_actor_mode, state_gateway_owner);
delay(C_GUI_DELAY_STATIC);
if (c_demo_mode)
delay(1000 * 60 * 10);
}
}
else
Expand Down
37 changes: 35 additions & 2 deletions independer-app/src/workflow/workflow-actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ void i_actor_functions_test_function_menu()
"Erreichbar-Check",
"Test Ausgabe",
"Test Datenaustausch",
"Zeit sync/anzeigen",
"Zeit anzeigen",
"[zurück]"};

bool fin_flag = false;
Expand All @@ -318,6 +320,17 @@ void i_actor_functions_test_function_menu()
gui_test();
else if (selected_wrapper.success and selected_wrapper.value == 2)
application_actor_large_data_test();
else if (selected_wrapper.success and selected_wrapper.value == 3)
{
gui_msg_static("Hinweis", "Frage Zeit\nab ...");
String r = time_sync_get_ntp();
gui_msg_animated("Zeit", "Empfangen\n'" + r + "'", C_GUI_DELAY_MSG_MIDDLE_I);
}
else if (selected_wrapper.success and selected_wrapper.value == 4)
{
String r = time_get_from_local();
gui_msg_animated("Zeit", "Lokal\n'" + r + "'", C_GUI_DELAY_MSG_MIDDLE_I);
}
else
fin_flag = true;
}
Expand Down Expand Up @@ -347,7 +360,7 @@ void i_actor_functions_menu()
}
else if (selected_wrapper.success and selected_wrapper.value == 2)
{
gui_input_char_no_output();
gui_input_char_no_output(true);
fin_flag = true;
}
else if (selected_wrapper.success and selected_wrapper.value == 3)
Expand Down Expand Up @@ -643,6 +656,14 @@ void i_settings_menu()
}
}

String i_workflow_rewrite_boolean(boolean value)
{
if (value)
return "Aktiv";
else
return "Inaktiv";
}

void workflow_actor_main_menu()
{
String menu_items[] = {
Expand All @@ -665,7 +686,19 @@ void workflow_actor_main_menu()
else if (selected_wrapper.success and selected_wrapper.value == 4)
{
gui_logo_static(c_product_version, state_my_id, state_gateway_id, c_actor_mode, state_gateway_owner);
delay(C_GUI_DELAY_STATIC);
gui_input_char_no_output(false);

gui_msg_static("Info (1/4)", "Version: " + c_product_version + "\nID: " + state_my_id + "\nGateway ID: " + state_gateway_id);
gui_input_char_no_output(false);

gui_msg_static("Info (2/4)", "Actor-Modus: " + i_workflow_rewrite_boolean(c_actor_mode) + "\nEntwickler: " + i_workflow_rewrite_boolean(c_dev_mode) + "\nLoRa-Gain: " + state_lora_gain);
gui_input_char_no_output(false);

gui_msg_static("Info (3/4)", "Helligkeit: " + String(state_oled_brightness) + "\nWIFI: " + state_wifi_ssid + "\nWIFI-Timeout: " + state_wifi_server_timeout);
gui_input_char_no_output(false);

gui_msg_static("Info (4/4)", "Hintergrundsync: " + i_workflow_rewrite_boolean(multi_actor_get_state()) + "\nBatterie: " + String(utils_get_battery()) + "mV\n" + time_get_from_local());
gui_input_char_no_output(false);
}
else if (selected_wrapper.success == false)
{
Expand Down
3 changes: 3 additions & 0 deletions independer-app/src/workflow/workflow-independer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ boolean workflow_independer_init(boolean isActor, String productVersion, boolean
{
Serial.println("- Init Dev Mode");
state_lora_gain = 6;

Serial.println("- Dev Mode Output");
time_debug_console_output();
}

Serial.println("[Finished Startup]");
Expand Down
5 changes: 5 additions & 0 deletions independer-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Docker is required.

- Add Users and Gateways in table `users` and `gateways`

#### Config Network

- Config Router DNS to server (local ip)
- Config Router to forward port to server

### Status

- `docker ps -a`
Expand Down

0 comments on commit c006823

Please sign in to comment.