diff --git a/README.md b/README.md index 4d66e032..5da145cb 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,11 @@ In other cases you can contact the developer via email: -#include "esp_wifi.h" -#include "esp_event_loop.h" -#include "freertos/event_groups.h" -#include "esp_log.h" - -#include -#include -#include -#include -#include - -#include - -#include "Helper.h" - - - - -static const char *MAIN_TAG = "connect_wlan"; - -std::string ssid = ""; -std::string passphrase = ""; -std::string hostname = ""; -std::string ipaddress = ""; -std::string gw = ""; -std::string netmask = ""; -std::string dns = ""; -std::string std_hostname = "watermeter"; - -static EventGroupHandle_t wifi_event_group; - - -#define BLINK_GPIO GPIO_NUM_33 - - -std::vector ZerlegeZeile(std::string input, std::string _delimiter = "") -{ - std::vector Output; - std::string delimiter = " =,"; - if (_delimiter.length() > 0){ - delimiter = _delimiter; - } - - input = trim(input, delimiter); - size_t pos = findDelimiterPos(input, delimiter); - std::string token; - while (pos != std::string::npos) { - token = input.substr(0, pos); - token = trim(token, delimiter); - Output.push_back(token); - input.erase(0, pos + 1); - input = trim(input, delimiter); - pos = findDelimiterPos(input, delimiter); - } - Output.push_back(input); - - return Output; -} - - - - -void wifi_connect(){ - wifi_config_t cfg = { }; - strcpy((char*)cfg.sta.ssid, (const char*)ssid.c_str()); - strcpy((char*)cfg.sta.password, (const char*)passphrase.c_str()); - - ESP_ERROR_CHECK( esp_wifi_disconnect() ); - ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &cfg) ); - ESP_ERROR_CHECK( esp_wifi_connect() ); -} - - - -void blinkstatus(int dauer, int _anzahl) -{ - gpio_reset_pin(BLINK_GPIO); - gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); - for (int i = 0; i < _anzahl; ++i) - { - gpio_set_level(BLINK_GPIO, 0); - vTaskDelay(dauer / portTICK_PERIOD_MS); - gpio_set_level(BLINK_GPIO, 1); - vTaskDelay(dauer / portTICK_PERIOD_MS); - } -} - -static esp_err_t event_handler(void *ctx, system_event_t *event) -{ - switch(event->event_id) { - case SYSTEM_EVENT_STA_START: - blinkstatus(200, 1); - wifi_connect(); - break; - case SYSTEM_EVENT_STA_GOT_IP: - xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); - blinkstatus(1000, 3); - break; - case SYSTEM_EVENT_STA_DISCONNECTED: - blinkstatus(200, 5); - esp_wifi_connect(); - xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); - break; - default: - break; - } - return ESP_OK; -} - -void initialise_wifi() -{ - ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL) ); - wifi_event_group = xEventGroupCreate(); - - esp_log_level_set("wifi", ESP_LOG_NONE); // disable wifi driver logging - tcpip_adapter_init(); - wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); - ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); - ESP_ERROR_CHECK( esp_wifi_start() ); - esp_err_t ret = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA , hostname.c_str()); - if(ret != ESP_OK ){ - ESP_LOGE(MAIN_TAG,"failed to set hostname:%d",ret); - } - xEventGroupWaitBits(wifi_event_group,CONNECTED_BIT,true,true,portMAX_DELAY); - tcpip_adapter_ip_info_t ip_info; - ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info)); - ipaddress = std::string(ip4addr_ntoa(&ip_info.ip)); - netmask = std::string(ip4addr_ntoa(&ip_info.netmask)); - gw = std::string(ip4addr_ntoa(&ip_info.gw)); - printf("IPv4 : %s\n", ip4addr_ntoa(&ip_info.ip)); - printf("HostName : %s\n", hostname.c_str()); -} - -/////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////// - -void strinttoip4(std::string ip, int &a, int &b, int &c, int &d) { - std::stringstream s(ip); - char ch; //to temporarily store the '.' - s >> a >> ch >> b >> ch >> c >> ch >> d; -} - -void initialise_wifi_fixed_ip() -{ - - wifi_event_group = xEventGroupCreate(); - - ESP_ERROR_CHECK(esp_netif_init()); - ESP_ERROR_CHECK(esp_event_loop_create_default()); - - esp_netif_t *my_sta = esp_netif_create_default_wifi_sta(); - - esp_netif_dhcpc_stop(my_sta); - - esp_netif_ip_info_t ip_info; - - int a, b, c, d; - - strinttoip4(ipaddress, a, b, c, d); - IP4_ADDR(&ip_info.ip, a, b, c, d); - - strinttoip4(gw, a, b, c, d); - IP4_ADDR(&ip_info.gw, a, b, c, d); - - strinttoip4(netmask, a, b, c, d); - IP4_ADDR(&ip_info.netmask, a, b, c, d); - - esp_netif_set_ip_info(my_sta, &ip_info); - - wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - ESP_ERROR_CHECK(esp_wifi_init(&cfg)); - - if (dns.length() > 0) { - esp_netif_dns_info_t dns_info; - ip4_addr_t ip; - ip.addr = esp_ip4addr_aton(dns.c_str()); - ip_addr_set_ip4_u32(&dns_info.ip, ip.addr); - ESP_ERROR_CHECK(esp_netif_set_dns_info(my_sta, ESP_NETIF_DNS_MAIN, &dns_info)); - } - - ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL) ); - - wifi_config_t wifi_config = { }; - strcpy((char*)wifi_config.sta.ssid, (const char*)ssid.c_str()); - strcpy((char*)wifi_config.sta.password, (const char*)passphrase.c_str()); - - ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); - ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) ); - ESP_ERROR_CHECK(esp_wifi_start() ); - - ESP_LOGI(MAIN_TAG, "wifi_init_sta finished."); - - EventBits_t bits = xEventGroupWaitBits(wifi_event_group,CONNECTED_BIT,true,true,portMAX_DELAY); - - if (bits & CONNECTED_BIT) { - ESP_LOGI(MAIN_TAG, "connected to ap SSID:%s password:%s", - ssid.c_str(), passphrase.c_str()); - } else { - ESP_LOGI(MAIN_TAG, "Failed to connect to SSID:%s, password:%s", - ssid.c_str(), passphrase.c_str()); - } - tcpip_adapter_ip_info_t ip_info2; - ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info2)); - ipaddress = std::string(ip4addr_ntoa(&ip_info2.ip)); - netmask = std::string(ip4addr_ntoa(&ip_info2.netmask)); - gw = std::string(ip4addr_ntoa(&ip_info2.gw)); - -// vEventGroupDelete(wifi_event_group); -} - - - -void ConnectToWLAN() -{ - if (ipaddress.length() == 0 || gw.length() == 0 || netmask.length() == 0) - { - printf("Connect to WLAN with dyn. IP\n"); - initialise_wifi(); - } - else - { - printf("Connect to WLAN with fixed IP\n"); - initialise_wifi_fixed_ip(); - } -} - - - -bool ChangeHostName(std::string fn, std::string _newhostname) -{ - if (_newhostname == hostname) - return false; - - string line = ""; - std::vector zerlegt; - - bool found = false; - - std::vector neuesfile; - - FILE* pFile; - fn = FormatFileName(fn); - pFile = OpenFileAndWait(fn.c_str(), "r"); - - printf("file loaded\n"); - - if (pFile == NULL) - return false; - - char zw[1024]; - fgets(zw, 1024, pFile); - line = std::string(zw); - - while ((line.size() > 0) || !(feof(pFile))) - { - printf("%s", line.c_str()); - zerlegt = ZerlegeZeile(line, "="); - zerlegt[0] = trim(zerlegt[0], " "); - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "HOSTNAME")){ - line = "hostname = \"" + _newhostname + "\"\n"; - found = true; - } - - neuesfile.push_back(line); - - if (fgets(zw, 1024, pFile) == NULL) - { - line = ""; - } - else - { - line = std::string(zw); - } - } - - if (!found) - { - line = "\nhostname = \"" + _newhostname + "\"\n"; - neuesfile.push_back(line); - } - - fclose(pFile); - - pFile = OpenFileAndWait(fn.c_str(), "w+"); - - for (int i = 0; i < neuesfile.size(); ++i) - { - printf(neuesfile[i].c_str()); - fputs(neuesfile[i].c_str(), pFile); - } - - fclose(pFile); - - printf("*** Update hostname done ***\n"); - - return true; -} - - -void LoadWlanFromFile(std::string fn) -{ - string line = ""; - std::vector zerlegt; - hostname = std_hostname; - - FILE* pFile; - fn = FormatFileName(fn); - - pFile = OpenFileAndWait(fn.c_str(), "r"); - printf("file loaded\n"); - - if (pFile == NULL) - return; - - char zw[1024]; - fgets(zw, 1024, pFile); - line = std::string(zw); - - while ((line.size() > 0) || !(feof(pFile))) - { - printf("%s", line.c_str()); - zerlegt = ZerlegeZeile(line, "="); - zerlegt[0] = trim(zerlegt[0], " "); - for (int i = 2; i < zerlegt.size(); ++i) - zerlegt[1] = zerlegt[1] + "=" + zerlegt[i]; - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "HOSTNAME")){ - hostname = trim(zerlegt[1]); - if ((hostname[0] == '"') && (hostname[hostname.length()-1] == '"')){ - hostname = hostname.substr(1, hostname.length()-2); - } - } - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "SSID")){ - ssid = trim(zerlegt[1]); - if ((ssid[0] == '"') && (ssid[ssid.length()-1] == '"')){ - ssid = ssid.substr(1, ssid.length()-2); - } - } - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "PASSWORD")){ - passphrase = zerlegt[1]; - if ((passphrase[0] == '"') && (passphrase[passphrase.length()-1] == '"')){ - passphrase = passphrase.substr(1, passphrase.length()-2); - } - } - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "IP")){ - ipaddress = zerlegt[1]; - if ((ipaddress[0] == '"') && (ipaddress[ipaddress.length()-1] == '"')){ - ipaddress = ipaddress.substr(1, ipaddress.length()-2); - } - } - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "GATEWAY")){ - gw = zerlegt[1]; - if ((gw[0] == '"') && (gw[gw.length()-1] == '"')){ - gw = gw.substr(1, gw.length()-2); - } - } - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "NETMASK")){ - netmask = zerlegt[1]; - if ((netmask[0] == '"') && (netmask[netmask.length()-1] == '"')){ - netmask = netmask.substr(1, netmask.length()-2); - } - } - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "DNS")){ - dns = zerlegt[1]; - if ((dns[0] == '"') && (dns[dns.length()-1] == '"')){ - dns = dns.substr(1, dns.length()-2); - } - } - - - if (fgets(zw, 1024, pFile) == NULL) - { - line = ""; - } - else - { - line = std::string(zw); - } - } - - fclose(pFile); - - // Check if Hostname was empty in .ini if yes set to std_hostname - if(hostname.length() <= 0){ - hostname = std_hostname; - } - - printf("\nWLan: %s, %s\n", ssid.c_str(), passphrase.c_str()); - printf("Hostename: %s\n", hostname.c_str()); - printf("Fixed IP: %s, Gateway %s, Netmask %s, DNS %s\n", ipaddress.c_str(), gw.c_str(), netmask.c_str(), dns.c_str()); - -} - -void LoadNetConfigFromFile(std::string fn, std::string &_ip, std::string &_gw, std::string &_netmask, std::string &_dns) -{ - string line = ""; - std::vector zerlegt; - - FILE* pFile; - fn = FormatFileName(fn); - pFile = OpenFileAndWait(fn.c_str(), "r"); - - printf("file loaded\n"); - - if (pFile == NULL) - return; - - char zw[1024]; - fgets(zw, 1024, pFile); - line = std::string(zw); - - while ((line.size() > 0) || !(feof(pFile))) - { - printf("%s", line.c_str()); - zerlegt = ZerlegeZeile(line, "="); - zerlegt[0] = trim(zerlegt[0], " "); - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "IP")){ - _ip = zerlegt[1]; - if ((_ip[0] == '"') && (_ip[_ip.length()-1] == '"')){ - _ip = _ip.substr(1, _ip.length()-2); - } - } - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "GATEWAY")){ - _gw = zerlegt[1]; - if ((_gw[0] == '"') && (_gw[_gw.length()-1] == '"')){ - _gw = _gw.substr(1, _gw.length()-2); - } - } - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "NETMASK")){ - _netmask = zerlegt[1]; - if ((_netmask[0] == '"') && (_netmask[_netmask.length()-1] == '"')){ - _netmask = _netmask.substr(1, _netmask.length()-2); - } - } - - if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "DNS")){ - _dns = zerlegt[1]; - if ((_dns[0] == '"') && (_dns[_dns.length()-1] == '"')){ - _dns = _dns.substr(1, _dns.length()-2); - } - } - - if (fgets(zw, 1024, pFile) == NULL) - { - line = ""; - } - else - { - line = std::string(zw); - } - } - - fclose(pFile); -} - - -std::string getHostname(){ - return hostname; -} - -std::string getIPAddress(){ - return ipaddress; -} - -std::string getSSID(){ - return ssid; -} - -std::string getNetMask(){ - return netmask; -} - -std::string getGW(){ - return gw; -} - diff --git a/code/components/connect_wlan/connect_wlan.h b/code/components/connect_wlan/connect_wlan.h deleted file mode 100644 index 827f32d2..00000000 --- a/code/components/connect_wlan/connect_wlan.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef CONNECT_WLAN_H -#define CONNECT_WLAN_H - -#include -#include "driver/gpio.h" - -const int CONNECTED_BIT = BIT0; -void ConnectToWLAN(); - -void LoadWlanFromFile(std::string fn); - -bool ChangeHostName(std::string fn, std::string _newhostname); - -std::string getHostname(); -std::string getIPAddress(); -std::string getSSID(); -std::string getNetMask(); -std::string getGW(); - -#endif \ No newline at end of file diff --git a/code/components/jomjol_flowcontroll/CMakeLists.txt b/code/components/jomjol_flowcontroll/CMakeLists.txt index de57d1cd..8a066910 100644 --- a/code/components/jomjol_flowcontroll/CMakeLists.txt +++ b/code/components/jomjol_flowcontroll/CMakeLists.txt @@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*) idf_component_register(SRCS ${app_sources} INCLUDE_DIRS "." - REQUIRES jomjol_tfliteclass jomjol_helper jomjol_controlcamera jomjol_mqtt jomjol_fileserver_ota jomjol_image_proc connect_wlan) + REQUIRES jomjol_tfliteclass jomjol_helper jomjol_controlcamera jomjol_mqtt jomjol_fileserver_ota jomjol_image_proc jomjol_wlan) diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp index 4bf307e2..e9020e7c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp @@ -1,6 +1,7 @@ #include "ClassFlowControll.h" #include "connect_wlan.h" +#include "read_wlanini.h" #include "freertos/task.h" diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 3e75827a..dfc5651d 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -158,7 +158,7 @@ bool ClassFlowMQTT::doFlow(string zwtime) { resulterror = " "; } - MQTTPublish(topicError, resulterror); + MQTTPublish(topicError, resulterror, 1); } if (topicRate.length() > 0) { diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp index dec910b5..8ba42fec 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.cpp +++ b/code/components/jomjol_mqtt/interface_mqtt.cpp @@ -16,11 +16,11 @@ esp_mqtt_event_id_t esp_mmqtt_ID = MQTT_EVENT_ANY; bool mqtt_connected = false; esp_mqtt_client_handle_t client = NULL; -void MQTTPublish(std::string _key, std::string _content){ +void MQTTPublish(std::string _key, std::string _content, int retained_flag){ if (client && mqtt_connected) { int msg_id; std::string zw; - msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, 0); + msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, retained_flag); zw = "sent publish successful in MQTTPublish, msg_id=" + std::to_string(msg_id) + ", " + _key + ", " + _content; if (debugdetail) LogFile.WriteToFile(zw); ESP_LOGI(TAG, "sent publish successful in MQTTPublish, msg_id=%d, %s, %s", msg_id, _key.c_str(), _content.c_str()); diff --git a/code/components/jomjol_mqtt/interface_mqtt.h b/code/components/jomjol_mqtt/interface_mqtt.h index 7ca5fa64..f514ea2d 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.h +++ b/code/components/jomjol_mqtt/interface_mqtt.h @@ -4,4 +4,4 @@ void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, st //void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user = "", std::string _password = ""); -void MQTTPublish(std::string _key, std::string _content); \ No newline at end of file +void MQTTPublish(std::string _key, std::string _content, int retained_flag = 0); \ No newline at end of file diff --git a/code/components/connect_wlan/CMakeLists.txt b/code/components/jomjol_wlan/CMakeLists.txt similarity index 73% rename from code/components/connect_wlan/CMakeLists.txt rename to code/components/jomjol_wlan/CMakeLists.txt index 8470774a..2887f8ca 100644 --- a/code/components/connect_wlan/CMakeLists.txt +++ b/code/components/jomjol_wlan/CMakeLists.txt @@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*) idf_component_register(SRCS ${app_sources} INCLUDE_DIRS "." - REQUIRES jomjol_helper) + REQUIRES nvs_flash jomjol_helper) diff --git a/code/components/jomjol_wlan/connect_wlan.cpp b/code/components/jomjol_wlan/connect_wlan.cpp new file mode 100644 index 00000000..3ebf422e --- /dev/null +++ b/code/components/jomjol_wlan/connect_wlan.cpp @@ -0,0 +1,289 @@ +#include "connect_wlan.h" + +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/event_groups.h" +#include "driver/gpio.h" +#include "esp_system.h" +#include "esp_wifi.h" +#include "esp_event.h" +#include "esp_log.h" +#include "nvs_flash.h" + +#include "lwip/err.h" +#include "lwip/sys.h" + +#include +#include +#include +#include +#include + + + +#define EXAMPLE_ESP_MAXIMUM_RETRY 1000 + +/* FreeRTOS event group to signal when we are connected*/ +static EventGroupHandle_t s_wifi_event_group; + +/* The event group allows multiple bits for each event, but we only care about two events: + * - we are connected to the AP with an IP + * - we failed to connect after the maximum amount of retries */ +#define WIFI_CONNECTED_BIT BIT0 +#define WIFI_FAIL_BIT BIT1 + +static const char *TAG = "wifi station"; + +static int s_retry_num = 0; + +/////////////////////////////////////////////////////////// +#define BLINK_GPIO GPIO_NUM_33 + +int BlinkDauer; +int BlinkAnzahl; +bool BlinkOff; +bool BlinkIsRunning = false; + +std::string hostname = ""; +std::string std_hostname = "watermeter"; +std::string ipadress = ""; +std::string ssid = ""; + +std::string getIPAddress() +{ + return ipadress; +} + +std::string getSSID() +{ + return ssid; +} + + +void task_doBlink(void *pvParameter) +{ + ESP_LOGI("BLINK", "Blinken - start"); + while (BlinkIsRunning) + { +// ESP_LOGI("BLINK", "Blinken - wait"); + vTaskDelay(100 / portTICK_PERIOD_MS); + } + + BlinkIsRunning = true; + + // Init the GPIO + gpio_pad_select_gpio(BLINK_GPIO); + /* Set the GPIO as a push/pull output */ + gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); + + for (int i = 0; i < BlinkAnzahl; ++i) + { + if (BlinkAnzahl > 1) + { + gpio_set_level(BLINK_GPIO, 1); + vTaskDelay(BlinkDauer / portTICK_PERIOD_MS); + } + gpio_set_level(BLINK_GPIO, 0); + vTaskDelay(BlinkDauer / portTICK_PERIOD_MS); + } + + if (BlinkOff) + gpio_set_level(BLINK_GPIO, 1); + + ESP_LOGI("BLINK", "Blinken - done"); + BlinkIsRunning = false; + + vTaskDelete(NULL); //Delete this task if it exits from the loop above +} + +void LEDBlinkTask(int _dauer, int _anz, bool _off) +{ + BlinkDauer = _dauer; + BlinkAnzahl = _anz; + BlinkOff = _off; + + xTaskCreate(&task_doBlink, "task_doBlink", configMINIMAL_STACK_SIZE * 8, NULL, tskIDLE_PRIORITY+1, NULL); +} +///////////////////////////////////////////////////////// + + +static void event_handler(void* arg, esp_event_base_t event_base, + int32_t event_id, void* event_data) +{ + if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { + LEDBlinkTask(200, 1, true); + esp_wifi_connect(); + } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { + if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) { +// LEDBlinkTask(200, 1, true); + esp_wifi_connect(); + s_retry_num++; + ESP_LOGI(TAG, "retry to connect to the AP"); + } else { + xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); + } + ESP_LOGI(TAG,"connect to the AP fail"); + } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { + ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; + ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); + ipadress = std::string(ip4addr_ntoa((const ip4_addr*) &event->ip_info.ip)); + s_retry_num = 0; + xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); + LEDBlinkTask(1000, 5, true); + } +} + +void strinttoip4(const char *ip, int &a, int &b, int &c, int &d) { + std::string zw = std::string(ip); + std::stringstream s(zw); + char ch; //to temporarily store the '.' + s >> a >> ch >> b >> ch >> c >> ch >> d; +} + + +void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostname, const char *_ipadr, const char *_gw, const char *_netmask, const char *_dns) +{ + ssid = std::string(_ssid); + + s_wifi_event_group = xEventGroupCreate(); + + ESP_ERROR_CHECK(esp_netif_init()); + ESP_ERROR_CHECK(esp_event_loop_create_default()); + +///////////////////////////////////////////////////////////////// + + + esp_netif_t *my_sta = esp_netif_create_default_wifi_sta(); + + if ((_ipadr != NULL) && (_gw != NULL) && (_netmask != NULL)) + { + ESP_LOGI(TAG, "set IP %s, GW %s, Netmask %s manual", _ipadr, _gw, _netmask); + esp_netif_dhcpc_stop(my_sta); + + esp_netif_ip_info_t ip_info; + int a, b, c, d; + strinttoip4(_ipadr, a, b, c, d); + IP4_ADDR(&ip_info.ip, a, b, c, d); + strinttoip4(_gw, a, b, c, d); + IP4_ADDR(&ip_info.gw, a, b, c, d); + strinttoip4(_netmask, a, b, c, d); + IP4_ADDR(&ip_info.netmask, a, b, c, d); + + esp_netif_set_ip_info(my_sta, &ip_info); + } + + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); + ESP_ERROR_CHECK(esp_wifi_init(&cfg)); + + if (_dns != NULL) { + ESP_LOGI(TAG, "set DNS manual"); + esp_netif_dns_info_t dns_info; + ip4_addr_t ip; + ip.addr = esp_ip4addr_aton(_dns); + ip_addr_set_ip4_u32(&dns_info.ip, ip.addr); + ESP_ERROR_CHECK(esp_netif_set_dns_info(my_sta, ESP_NETIF_DNS_MAIN, &dns_info)); + } +///////////////////////////////////////////////////////////////// + + +// esp_netif_create_default_wifi_sta(); + +// wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); +// ESP_ERROR_CHECK(esp_wifi_init(&cfg)); + + + +/* +////////////////////////////// esp-idf 4.2 ////////////////////////// + esp_event_handler_instance_t instance_any_id; + esp_event_handler_instance_t instance_got_ip; + ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, + ESP_EVENT_ANY_ID, + &event_handler, + NULL, + &instance_any_id)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, + IP_EVENT_STA_GOT_IP, + &event_handler, + NULL, + &instance_got_ip)); +////////////////////////// ENDE esp-idf 4.2 /////////////////////////// +*/ + + ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); + ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL)); + + wifi_config_t wifi_config = { }; + + strcpy((char*)wifi_config.sta.ssid, (const char*)_ssid); + strcpy((char*)wifi_config.sta.password, (const char*)_password); + + ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); + ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) ); + ESP_ERROR_CHECK(esp_wifi_start() ); + + if (_hostname != NULL) + { + esp_err_t ret = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA , _hostname); + hostname = std::string(_hostname); + if(ret != ESP_OK ){ + ESP_LOGE(TAG,"failed to set hostname:%d",ret); + } + } + + ESP_LOGI(TAG, "wifi_init_sta finished."); + + /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum + * number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */ + EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, + WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, + pdFALSE, + pdFALSE, + portMAX_DELAY); + + /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually + * happened. */ + if (bits & WIFI_CONNECTED_BIT) { + ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", + _ssid, _password); + } else if (bits & WIFI_FAIL_BIT) { + ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", + _ssid, _password); + } else { + ESP_LOGE(TAG, "UNEXPECTED EVENT"); + } + + /* The event will not be processed after unregister */ +/* +////////////////////////////// esp-idf 4.2 ////////////////////////// + ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, instance_got_ip)); + ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, instance_any_id)); +////////////////////////// ENDE esp-idf 4.2 /////////////////////////// +*/ + + ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler)); + ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler)); + + + vEventGroupDelete(s_wifi_event_group); + +/* + while (BlinkIsRunning) + { + vTaskDelay(100 / portTICK_PERIOD_MS); + } +*/ +} + + +void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostname) +{ + wifi_init_sta(_ssid, _password, _hostname, NULL, NULL, NULL, NULL); +} + +void wifi_init_sta(const char *_ssid, const char *_password) +{ + wifi_init_sta(_ssid, _password, NULL, NULL, NULL, NULL, NULL); +} + diff --git a/code/components/jomjol_wlan/connect_wlan.h b/code/components/jomjol_wlan/connect_wlan.h new file mode 100644 index 00000000..29f9889a --- /dev/null +++ b/code/components/jomjol_wlan/connect_wlan.h @@ -0,0 +1,16 @@ +#ifndef CONNECT_WLAN_H +#define CONNECT_WLAN_H + +#include + +void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostname, const char *_ipadr, const char *_gw, const char *_netmask, const char *_dns); +void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostname); +void wifi_init_sta(const char *_ssid, const char *_password); + +std::string getIPAddress(); +std::string getSSID(); + +extern std::string hostname; +extern std::string std_hostname; + +#endif \ No newline at end of file diff --git a/code/components/jomjol_wlan/read_wlanini.cpp b/code/components/jomjol_wlan/read_wlanini.cpp new file mode 100644 index 00000000..dcf28a47 --- /dev/null +++ b/code/components/jomjol_wlan/read_wlanini.cpp @@ -0,0 +1,257 @@ +#include "read_wlanini.h" + +#include "Helper.h" + +#include "connect_wlan.h" + +#include +#include +#include +#include +#include +#include + + +std::vector ZerlegeZeile(std::string input, std::string _delimiter = "") +{ + std::vector Output; + std::string delimiter = " =,"; + if (_delimiter.length() > 0){ + delimiter = _delimiter; + } + + input = trim(input, delimiter); + size_t pos = findDelimiterPos(input, delimiter); + std::string token; + while (pos != std::string::npos) { + token = input.substr(0, pos); + token = trim(token, delimiter); + Output.push_back(token); + input.erase(0, pos + 1); + input = trim(input, delimiter); + pos = findDelimiterPos(input, delimiter); + } + Output.push_back(input); + + return Output; +} + + + +void LoadWlanFromFile(std::string fn, char *&_ssid, char *&_password, char *&_hostname, char *&_ipadr, char *&_gw, char *&_netmask, char *&_dns) +{ + std::string ssid = ""; + std::string passphrase = ""; + std::string ipaddress = ""; + std::string gw = ""; + std::string netmask = ""; + std::string dns = ""; + + std::string line = ""; + std::vector zerlegt; + hostname = std_hostname; + + FILE* pFile; + fn = FormatFileName(fn); + + pFile = OpenFileAndWait(fn.c_str(), "r"); + printf("file loaded\n"); + + if (pFile == NULL) + return; + + char zw[1024]; + fgets(zw, 1024, pFile); + line = std::string(zw); + + while ((line.size() > 0) || !(feof(pFile))) + { +// printf("%s", line.c_str()); + zerlegt = ZerlegeZeile(line, "="); + zerlegt[0] = trim(zerlegt[0], " "); + for (int i = 2; i < zerlegt.size(); ++i) + zerlegt[1] = zerlegt[1] + zerlegt[i]; + + if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "HOSTNAME")){ + hostname = trim(zerlegt[1]); + if ((hostname[0] == '"') && (hostname[hostname.length()-1] == '"')){ + hostname = hostname.substr(1, hostname.length()-2); + } + } + + if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "SSID")){ + ssid = trim(zerlegt[1]); + if ((ssid[0] == '"') && (ssid[ssid.length()-1] == '"')){ + ssid = ssid.substr(1, ssid.length()-2); + } + } + + if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "PASSWORD")){ + passphrase = zerlegt[1]; + if ((passphrase[0] == '"') && (passphrase[passphrase.length()-1] == '"')){ + passphrase = passphrase.substr(1, passphrase.length()-2); + } + } + + if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "IP")){ + ipaddress = zerlegt[1]; + if ((ipaddress[0] == '"') && (ipaddress[ipaddress.length()-1] == '"')){ + ipaddress = ipaddress.substr(1, ipaddress.length()-2); + } + } + + if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "GATEWAY")){ + gw = zerlegt[1]; + if ((gw[0] == '"') && (gw[gw.length()-1] == '"')){ + gw = gw.substr(1, gw.length()-2); + } + } + + if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "NETMASK")){ + netmask = zerlegt[1]; + if ((netmask[0] == '"') && (netmask[netmask.length()-1] == '"')){ + netmask = netmask.substr(1, netmask.length()-2); + } + } + + if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "DNS")){ + dns = zerlegt[1]; + if ((dns[0] == '"') && (dns[dns.length()-1] == '"')){ + dns = dns.substr(1, dns.length()-2); + } + } + + + if (fgets(zw, 1024, pFile) == NULL) + { + line = ""; + } + else + { + line = std::string(zw); + } + } + + fclose(pFile); + + // Check if Hostname was empty in .ini if yes set to std_hostname + if(hostname.length() >= 0){ + hostname = std_hostname; + } + + _hostname = new char[hostname.length() + 1]; + strcpy(_hostname, hostname.c_str()); + + _ssid = new char[ssid.length() + 1]; + strcpy(_ssid, ssid.c_str()); + + _password = new char[passphrase.length() + 1]; + strcpy(_password, passphrase.c_str()); + + if (ipaddress.length() > 0) + { + _ipadr = new char[ipaddress.length() + 1]; + strcpy(_ipadr, ipaddress.c_str()); + } + else + _ipadr = NULL; + + if (gw.length() > 0) + { + _gw = new char[gw.length() + 1]; + strcpy(_gw, gw.c_str()); + } + else + _gw = NULL; + + if (netmask.length() > 0) + { + _netmask = new char[netmask.length() + 1]; + strcpy(_netmask, netmask.c_str()); + } + else + _netmask = NULL; + + if (dns.length() > 0) + { + _dns = new char[dns.length() + 1]; + strcpy(_dns, dns.c_str()); + } + else + _dns = NULL; +} + + + + +bool ChangeHostName(std::string fn, std::string _newhostname) +{ + if (_newhostname == hostname) + return false; + + string line = ""; + std::vector zerlegt; + + bool found = false; + + std::vector neuesfile; + + FILE* pFile; + fn = FormatFileName(fn); + pFile = OpenFileAndWait(fn.c_str(), "r"); + + printf("file loaded\n"); + + if (pFile == NULL) + return false; + + char zw[1024]; + fgets(zw, 1024, pFile); + line = std::string(zw); + + while ((line.size() > 0) || !(feof(pFile))) + { + printf("%s", line.c_str()); + zerlegt = ZerlegeZeile(line, "="); + zerlegt[0] = trim(zerlegt[0], " "); + + if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "HOSTNAME")){ + line = "hostname = \"" + _newhostname + "\"\n"; + found = true; + } + + neuesfile.push_back(line); + + if (fgets(zw, 1024, pFile) == NULL) + { + line = ""; + } + else + { + line = std::string(zw); + } + } + + if (!found) + { + line = "\nhostname = \"" + _newhostname + "\"\n"; + neuesfile.push_back(line); + } + + fclose(pFile); + + pFile = OpenFileAndWait(fn.c_str(), "w+"); + + for (int i = 0; i < neuesfile.size(); ++i) + { + printf(neuesfile[i].c_str()); + fputs(neuesfile[i].c_str(), pFile); + } + + fclose(pFile); + + printf("*** Update hostname done ***\n"); + + return true; +} + diff --git a/code/components/jomjol_wlan/read_wlanini.h b/code/components/jomjol_wlan/read_wlanini.h new file mode 100644 index 00000000..f406bb1a --- /dev/null +++ b/code/components/jomjol_wlan/read_wlanini.h @@ -0,0 +1,11 @@ +#ifndef READ_WLANINI_H +#define READ_WLANINI_H + +#include + +void LoadWlanFromFile(std::string fn, char *&_ssid, char *&_password, char *&_hostname, char *&_ipadr, char *&_gw, char *&_netmask, char *&_dns); + +bool ChangeHostName(std::string fn, std::string _newhostname); + + +#endif \ No newline at end of file diff --git a/code/main/main._c_p_p b/code/main/main._c_p_p new file mode 100644 index 00000000..493ff17b --- /dev/null +++ b/code/main/main._c_p_p @@ -0,0 +1,188 @@ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/event_groups.h" + +#include "driver/gpio.h" +#include "sdkconfig.h" + +// SD-Card //////////////////// +#include "nvs_flash.h" +#include "esp_vfs_fat.h" +#include "sdmmc_cmd.h" +#include "driver/sdmmc_host.h" +#include "driver/sdmmc_defs.h" +/////////////////////////////// + +#include "ClassLogFile.h" + +#include "connect_wlan.h" + +#include "server_tflite.h" +#include "server_file.h" +#include "server_ota.h" +#include "time_sntp.h" +#include "ClassControllCamera.h" +#include "server_main.h" +#include "server_camera.h" + + +#define __SD_USE_ONE_LINE_MODE__ + +#ifdef __SD_USE_ONE_LINE_MODE__ +#include "server_GPIO.h" +#endif + + +#define BLINK_GPIO GPIO_NUM_33 + +static const char *TAGMAIN = "connect_wlan_main"; + +#define FLASH_GPIO GPIO_NUM_4 + +bool Init_NVS_SDCard() +{ + esp_err_t ret = nvs_flash_init(); + if (ret == ESP_ERR_NVS_NO_FREE_PAGES) { + ESP_ERROR_CHECK(nvs_flash_erase()); + ret = nvs_flash_init(); + } +//////////////////////////////////////////////// + + ESP_LOGI(TAG, "Using SDMMC peripheral"); + sdmmc_host_t host = SDMMC_HOST_DEFAULT(); + + // This initializes the slot without card detect (CD) and write protect (WP) signals. + // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals. + sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); + + // To use 1-line SD mode, uncomment the following line: + +#ifdef __SD_USE_ONE_LINE_MODE__ + slot_config.width = 1; +#endif + + // GPIOs 15, 2, 4, 12, 13 should have external 10k pull-ups. + // Internal pull-ups are not sufficient. However, enabling internal pull-ups + // does make a difference some boards, so we do that here. + gpio_set_pull_mode(GPIO_NUM_15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes + gpio_set_pull_mode(GPIO_NUM_2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes + gpio_set_pull_mode(GPIO_NUM_4, GPIO_PULLUP_ONLY); // D1, needed in 4-line mode only + gpio_set_pull_mode(GPIO_NUM_12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only + gpio_set_pull_mode(GPIO_NUM_13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes + + // Options for mounting the filesystem. + // If format_if_mount_failed is set to true, SD card will be partitioned and + // formatted in case when mounting fails. + esp_vfs_fat_sdmmc_mount_config_t mount_config = { + .format_if_mount_failed = false, + .max_files = 5, + .allocation_unit_size = 16 * 1024 + }; + + // Use settings defined above to initialize SD card and mount FAT filesystem. + // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function. + // Please check its source code and implement error recovery when developing + // production applications. + sdmmc_card_t* card; + ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card); + + if (ret != ESP_OK) { + if (ret == ESP_FAIL) { + ESP_LOGE(TAG, "Failed to mount filesystem. " + "If you want the card to be formatted, set format_if_mount_failed = true."); + } else { + ESP_LOGE(TAG, "Failed to initialize the card (%s). " + "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret)); + } + return false; + } + + // Card has been initialized, print its properties + sdmmc_card_print_info(stdout, card); + + + // Init the GPIO + // Flash ausschalten + gpio_pad_select_gpio(FLASH_GPIO); + gpio_set_direction(FLASH_GPIO, GPIO_MODE_OUTPUT); + gpio_set_level(FLASH_GPIO, 0); + + return true; +} + +void task_NoSDBlink(void *pvParameter) +{ + gpio_pad_select_gpio(BLINK_GPIO); + gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); + + + TickType_t xDelay; + xDelay = 100 / portTICK_PERIOD_MS; + printf("SD-Card could not be inialized - STOP THE PROGRAMM HERE\n"); + + while (1) + { + gpio_set_level(BLINK_GPIO, 1); + vTaskDelay( xDelay ); + gpio_set_level(BLINK_GPIO, 0); + vTaskDelay( xDelay ); + + } + vTaskDelete(NULL); //Delete this task if it exits from the loop above +} + +extern "C" void app_main(void) +{ + printf("Do Reset Camera\n"); + PowerResetCamera(); + Camera.InitCam(); + Camera.LightOnOff(false); + + if (!Init_NVS_SDCard()) + { + xTaskCreate(&task_NoSDBlink, "task_NoSDBlink", configMINIMAL_STACK_SIZE * 64, NULL, tskIDLE_PRIORITY+1, NULL); + return; + }; + + CheckOTAUpdate(); + + LoadWlanFromFile("/sdcard/wlan.ini"); + ConnectToWLAN(); + printf("\nNetparameter: IP: %s - GW: %s - NetMask %s\n", getIPAddress().c_str(), getGW().c_str(), getNetMask().c_str()); + + TickType_t xDelay; + xDelay = 2000 / portTICK_PERIOD_MS; + printf("Autoflow: sleep for : %ldms\n", (long) xDelay); +// LogFile.WriteToFile("Startsequence 06"); + vTaskDelay( xDelay ); +// LogFile.WriteToFile("Startsequence 07"); + setup_time(); + LogFile.WriteToFile("============================================================================================="); + LogFile.WriteToFile("=================================== Main Started ============================================"); + LogFile.WriteToFile("============================================================================================="); + LogFile.SwitchOnOff(false); + + std::string zw = gettimestring("%Y%m%d-%H%M%S"); + printf("time %s\n", zw.c_str()); + +// Camera.InitCam(); +// Camera.LightOnOff(false); + xDelay = 2000 / portTICK_PERIOD_MS; + printf("Autoflow: sleep for : %ldms\n", (long) xDelay); + vTaskDelay( xDelay ); + + server = start_webserver(); + register_server_camera_uri(server); + register_server_tflite_uri(server); + register_server_file_uri(server, "/sdcard"); + register_server_ota_sdcard_uri(server); + +#ifdef __SD_USE_ONE_LINE_MODE__ + register_server_GPIO_uri(server); +#endif + + register_server_main_uri(server, "/sdcard"); + + TFliteDoAutoStart(); +} diff --git a/code/main/main.cpp b/code/main/main.cpp index 493ff17b..eda84e83 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -17,6 +17,7 @@ #include "ClassLogFile.h" #include "connect_wlan.h" +#include "read_wlanini.h" #include "server_tflite.h" #include "server_file.h" @@ -30,7 +31,7 @@ #define __SD_USE_ONE_LINE_MODE__ #ifdef __SD_USE_ONE_LINE_MODE__ -#include "server_GPIO.h" +// #include "server_GPIO.h" #endif @@ -67,8 +68,10 @@ bool Init_NVS_SDCard() // does make a difference some boards, so we do that here. gpio_set_pull_mode(GPIO_NUM_15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes gpio_set_pull_mode(GPIO_NUM_2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes +#ifndef __SD_USE_ONE_LINE_MODE__ gpio_set_pull_mode(GPIO_NUM_4, GPIO_PULLUP_ONLY); // D1, needed in 4-line mode only gpio_set_pull_mode(GPIO_NUM_12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only +#endif gpio_set_pull_mode(GPIO_NUM_13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes // Options for mounting the filesystem. @@ -104,6 +107,7 @@ bool Init_NVS_SDCard() // Init the GPIO // Flash ausschalten + gpio_pad_select_gpio(FLASH_GPIO); gpio_set_direction(FLASH_GPIO, GPIO_MODE_OUTPUT); gpio_set_level(FLASH_GPIO, 0); @@ -147,9 +151,26 @@ extern "C" void app_main(void) CheckOTAUpdate(); - LoadWlanFromFile("/sdcard/wlan.ini"); - ConnectToWLAN(); - printf("\nNetparameter: IP: %s - GW: %s - NetMask %s\n", getIPAddress().c_str(), getGW().c_str(), getNetMask().c_str()); + char *ssid = NULL, *passwd = NULL, *hostname = NULL, *ip = NULL, *gateway = NULL, *netmask = NULL, *dns = NULL; + LoadWlanFromFile("/sdcard/wlan.ini", ssid, passwd, hostname, ip, gateway, netmask, dns); + + if (ssid != NULL && passwd != NULL) + printf("\nWLan: %s, %s\n", ssid, passwd); + else + printf("No SSID and PASSWORD set!!!"); + + if (hostname != NULL) + printf("Hostename: %s\n", hostname); + else + printf("Hostname not set.\n"); + + if (ip != NULL && gateway != NULL && netmask != NULL) + printf("Fixed IP: %s, Gateway %s, Netmask %s\n", ip, gateway, netmask); + if (dns != NULL) + printf("DNS IP: %s\n", dns); + + + wifi_init_sta(ssid, passwd, hostname, ip, gateway, netmask, dns); TickType_t xDelay; xDelay = 2000 / portTICK_PERIOD_MS; @@ -179,10 +200,12 @@ extern "C" void app_main(void) register_server_ota_sdcard_uri(server); #ifdef __SD_USE_ONE_LINE_MODE__ - register_server_GPIO_uri(server); +// register_server_GPIO_uri(server); #endif + printf("vor reg server main\n"); register_server_main_uri(server, "/sdcard"); + printf("vor dotautostart\n"); TFliteDoAutoStart(); } diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index fb5df4ee..ba31c09c 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -107,7 +107,7 @@ esp_err_t info_get_handler(httpd_req_t *req) if (_task.compare("Hostname") == 0) { std::string zw; - zw = std::string(getHostname()); + zw = std::string(hostname); httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr_chunk(req, NULL); return ESP_OK; diff --git a/code/main/version.cpp b/code/main/version.cpp index 4c75d61a..73339c44 100644 --- a/code/main/version.cpp +++ b/code/main/version.cpp @@ -1,4 +1,4 @@ -const char* GIT_REV="b7e6d33"; +const char* GIT_REV="39eda4a"; const char* GIT_TAG=""; -const char* GIT_BRANCH="master"; -const char* BUILD_TIME="2021-05-13 08:18"; \ No newline at end of file +const char* GIT_BRANCH="rolling"; +const char* BUILD_TIME="2021-05-17 19:21"; \ No newline at end of file diff --git a/code/platformio.ini b/code/platformio.ini index f42f3aa1..50bf0706 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -24,7 +24,7 @@ board_build.partitions = partitions.csv lib_deps = jomjol_helper - connect_wlan + jomjol_wlan jomjol_image_proc jomjol_controlcamera jomjol_flowcontroll diff --git a/code/version.cpp b/code/version.cpp index 4c75d61a..73339c44 100644 --- a/code/version.cpp +++ b/code/version.cpp @@ -1,4 +1,4 @@ -const char* GIT_REV="b7e6d33"; +const char* GIT_REV="39eda4a"; const char* GIT_TAG=""; -const char* GIT_BRANCH="master"; -const char* BUILD_TIME="2021-05-13 08:18"; \ No newline at end of file +const char* GIT_BRANCH="rolling"; +const char* BUILD_TIME="2021-05-17 19:21"; \ No newline at end of file diff --git a/firmware/bootloader.bin b/firmware/bootloader.bin index 7abe8218..fa726ffd 100644 Binary files a/firmware/bootloader.bin and b/firmware/bootloader.bin differ diff --git a/firmware/firmware.bin b/firmware/firmware.bin index 63f4ca00..ce98695b 100644 Binary files a/firmware/firmware.bin and b/firmware/firmware.bin differ