-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't find the ssid on my network NMEA Bridge #5
Comments
Did it compile and flash without errors; what was the logging output? |
C:\Arduino Ockam ersatz\nmea-bridge-main\nmea_bridge\nmea_bridge.ino: In function 'void handle_udp_event()':
C:\Arduino Ockam ersatz\nmea-bridge-main\nmea_bridge\nmea_bridge.ino:513:54: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
513 | handle_incoming_sentence(buffer, length, "udp");
| ^~~~~
C:\Arduino Ockam ersatz\nmea-bridge-main\nmea_bridge\nmea_bridge.ino: In function 'void handle_websocket_event(uint8_t, WStype_t, uint8_t*, size_t)':
C:\Arduino Ockam ersatz\nmea-bridge-main\nmea_bridge\nmea_bridge.ino:533:63: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
533 | handle_incoming_sentence((char *)payload, length, "ws");
| ^~~~
C:\Arduino Ockam ersatz\nmea-bridge-main\nmea_bridge\nmea_bridge.ino: In function 'void transmit_outgoing_over_websocket(char*, size_t)':
C:\Arduino Ockam ersatz\nmea-bridge-main\nmea_bridge\nmea_bridge.ino:589:50: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
589 | send_websocket_message(sentence, length, "serial");
| ^~~~~~~~
C:\Arduino Ockam ersatz\nmea-bridge-main\nmea_bridge\nmea_bridge.ino: In function 'void send_websocket_message(char*, size_t, char*)':
C:\Arduino Ockam ersatz\nmea-bridge-main\nmea_bridge\nmea_bridge.ino:603:54: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
603 | write_format_to_http_response_buffer("\\u%04x", int(c));
| ^~~~~~~~~
. Variables and constants in RAM (global, static), used 42204 / 80192 bytes (52%)
║ SEGMENT BYTES DESCRIPTION
╠══ DATA 1632 initialized variables
╠══ RODATA 8668 constants
╚══ BSS 31904 zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 60863 / 65536 bytes (92%)
║ SEGMENT BYTES DESCRIPTION
╠══ ICACHE 32768 reserved space for flash instruction cache
╚══ IRAM 28095 code in IRAM
. Code in flash (default, ICACHE_FLASH_ATTR), used 316280 / 1048576 bytes (30%)
║ SEGMENT BYTES DESCRIPTION
╚══ IROM 316280 code in flash
esptool.py v3.0
Serial port COM9
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 84:0d:8e:a7:73:22
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 358832 bytes to 256751...
Writing at 0x00000000... (6 %)
Writing at 0x00004000... (12 %)
Writing at 0x00008000... (18 %)
Writing at 0x0000c000... (25 %)
Writing at 0x00010000... (31 %)
Writing at 0x00014000... (37 %)
Writing at 0x00018000... (43 %)
Writing at 0x0001c000... (50 %)
Writing at 0x00020000... (56 %)
Writing at 0x00024000... (62 %)
Writing at 0x00028000... (68 %)
Writing at 0x0002c000... (75 %)
Writing at 0x00030000... (81 %)
Writing at 0x00034000... (87 %)
Writing at 0x00038000... (93 %)
Writing at 0x0003c000... (100 %)
Wrote 358832 bytes (256751 compressed) at 0x00000000 in 6.2 seconds (effective 461.7 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
Gesendet: Mittwoch, 06. Dezember 2023 um 17:02 Uhr
Von: "Alexander van Ratingen" ***@***.***>
An: "alvra/nmea-bridge" ***@***.***>
Cc: "bbgt0814" ***@***.***>, "Author" ***@***.***>
Betreff: Re: [alvra/nmea-bridge] can't find the ssid on my network NMEA Bridge (Issue #5)
Did it compile and flash without errors; what was the logging output?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
I tried it with both Arduino IDE Versions 1.8X and 2.X, the error remains the same. Greetings |
Hi, questions about the problem described. on which board was the sketch originally developed? which lib and which IDE compiler version does the sketch work? Is there currently a board on which the sketch can run? |
Hello, Having a similar issue with HiLetgo NodeMCU LUA ESP8266 Looking through the code, I am getting a double blink which indicates I am in access point mode but there is no SSID showing up on any of my devices. Any thoughts on where to go from here? |
Some information that may be helpful to you: If the device was properly flashed and otherwise seems to function but you're not seeing a WiFi access point, it might be that the device is accidentally configured into station mode. Try to reset it as explained in the readme, and see if the AP |
I've been through everything. I assume that the eeprom is addressed incorrectly.
I gave up the project because all work with the sketch was not productive.
The new IDE no longer works as expected. Process too complex.
Gesendet: Montag, 08. Januar 2024 um 22:42 Uhr
Von: "Alexander van Ratingen" ***@***.***>
An: "alvra/nmea-bridge" ***@***.***>
Cc: "bbgt0814" ***@***.***>, "Author" ***@***.***>
Betreff: Re: [alvra/nmea-bridge] can't find the ssid on my network NMEA Bridge (Issue #5)
Some information that may be helpful to you:
Original device for which this was developed: NodeMCU v3
Arduino IDE version: 1.8.19 (2021)
Board config in IDE: NodeMCU 1.0 (ESP-12E Module)
If the device was properly flashed and otherwise seems to function but you're not seeing a WiFi access point, it might be that the device is accidentally configured into station mode. Try to reset it as explained in the readme, and see if the AP NMEA Bridge appears.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Had the same problem. The ESP8266 came up with an access point SSID of FARYLINK-*******, password unknown. To cut a long story short, I was not able to reset the module on boot. So I added a button to an unused GPIO input and changed the code just to check if that button is pressed. Then bingo, I got the NEMA-Bridge SSID successfully. |
I assume there is a timing problem when booting. The solution with the initial query does not show a 100% solution to the problem
Gesendet: Freitag, 09. Februar 2024 um 11:20 Uhr
Von: "Fire-Power" ***@***.***>
An: "alvra/nmea-bridge" ***@***.***>
Cc: "bbgt0814" ***@***.***>, "Author" ***@***.***>
Betreff: Re: [alvra/nmea-bridge] can't find the ssid on my network NMEA Bridge (Issue #5)
Had the same problem. The ESP8266 came up with an access point SSID of FARYLINK-*******, password unknown. To cut a long story short, I was not able to reset the module on boot. So I added a button to an unused GPIO input and changed the code just to check if that button is pressed. Then bingo, I got the NEMA-Bridge SSID successfully.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
@alvra I'm having the exact same problem. I get the network ESP-5D3CAE and I cannot connect to it. The reset button on the board doesn't work as well :( @Fire-Power can you please share the example of your code? I'd spent 5+ hours trying different solutions that came to my mind - nothing works. |
The version with a reset config button added. #include <dummy.h> #include <Arduino.h> extern "C" { // global macros utils #define DEBUG #define DEBUG_SERIAL Serial #ifdef DEBUG // #define DEBUG_PRINT(x) DEBUG_SERIAL.print(x) #define min(x, y) ((x < y) ? x : y) // hardware layout #define CONFIG_EEPROM_ADDRESS 100 #define WIFI_SIGNAL_POWER 20.5 // min: 0 - max: 20.5 dBm #define BOOT_MODE_BUTTON_PIN 0 #define INDICATOR_LED_PIN 4 // D2 pin 13 //#define LAMP1 4 #define RESET_CONFIG_THRESHOLD 5000 // in milliseconds // configuration #define MAX_WIFI_SSID_SIZE 33 #define ENABLE_WEBSOCKET_LOG enum WifiMode: uint8_t { enum TransmitMode: uint8_t { #define BAUDRATE_OPTION_COUNT 4 /* // The serial device on which this device receives NMEA sentences. // The serial device on which this device transmits NMEA sentences. // Set to 1 if the RX and TX serial ports are the same one. struct Configuration { const char* display_wifi_mode(WifiMode mode) { const char* display_tx_mode(TransmitMode mode) { struct Configuration default_config = { // global values #define HTTP_PORT 80 #define WIFI_ACCESS_POINT_CHANNEL 6 bool inConfigMode = false; bool sentence_wanted = false; #define UDP_SENTENCE_BUFFER_SIZE 1000 #define HTTP_RESPONSE_BUFFER_SIZE 4000 /* The buffer should be long enough for about two sentences ESP8266WebServer http_server(HTTP_PORT); // cache static files "forever" (about a year) /* Create a request handler for static files. // forward declarations void send_info_page_response(); void update_mdns_hostname(); void set_indicator_led_on(); String get_uptime_display(); void load_config_from_eeprom(Configuration &new_config); #include "html_fragments.cpp" // TODO inherit WEBSOCKET_PORT extern const String html_start; /********************** void setup() {
// pinMode(BOOT_MODE_BUTTON_PIN, INPUT_PULLUP);
} void loop() {
// if (digitalRead(BUTTON1)) {
} /********************* void handle_serial_event() {
// digitalWrite(LAMP2,HIGH);
} void handle_udp_event() {
} #ifdef ENABLE_WEBSOCKET_LOG
#endif void handle_incoming_sentence(char *sentence, size_t length, char source) {
} void filter_unwanted_sentence(char *sentence, size_t length) {
//DEBUG_SERIAL.print(sentence);
} void handle_outgoing_sentence(char sentence, size_t length) {
//digitalWrite(LAMP2,LOW); // transmit_incoming_over_serial(sentence, length); // Added to loop back on NEMA
} void transmit_incoming_over_serial(char *sentence, size_t length) { // int freetxbuf = SERIAL_TX.availableForWrite(); void buffer_outgoing_serial(char *sentence, size_t length) { } void transmit_outgoing_over_udp(char *sentence, size_t length) {
} #ifdef ENABLE_WEBSOCKET_LOG
#endif /****************************** bool isThisHost(String host) { bool captive_portal() { void clear_http_response_buffer() {
} void send_http_response_buffer() { const String html_link(String url, String text) { void write_info_html_section_start(const char *title) { ");"); |
"); write_to_http_response_buffer(name); write_to_http_response_buffer(" | "); write_to_http_response_buffer(value); write_to_http_response_buffer(" |
---|
}
void send_info_page_response() {
/* Request handler for the info page.
*/
if (captive_portal()) {return;}
String device_ip = get_device_ip_address().toString();
write_to_http_response_buffer(html_start);
write_info_html_section_start("Network");
if (is_network_config_changed) {
write_to_http_response_buffer(
"<p class=\"note\">"
"The network configuration has been updated "
"since the device started. "
"Changes will be applied after restart."
"</p>");
}
write_info_html_field(
"Wifi mode",
display_wifi_mode(effective_wifi_mode));
write_info_html_field(
"Wifi SSID",
effective_wifi_ssid);
write_info_html_field(
"IP Address",
device_ip);
write_info_html_field(
"Hostname",
config.mdns_hostname[0] == '\0' ?
"undefined" :
html_link(
String("http://") + config.mdns_hostname + String(".local/"),
config.mdns_hostname));
write_info_html_field(
"MAC Address",
WiFi.macAddress());
if (effective_wifi_mode == WifiMode::access_point) {
write_info_html_field(
"Connected Stations",
String(WiFi.softAPgetStationNum()));
}
write_info_html_section_end();
write_info_html_section_start("Connection");
write_info_html_field(
"Transmit Mode",
display_tx_mode(config.tx_mode));
String tx_addr = (
String("udp://") + effective_tx_address.toString()
+ String(":") + String(config.tx_port));
write_info_html_field(
"Transmit",
html_link(tx_addr, tx_addr));
String rx_addr = (
String("udp://") + device_ip + String(":") + String(config.rx_port));
write_info_html_field(
"Receive",
html_link(rx_addr, rx_addr));
write_info_html_section_end();
write_info_html_section_start("Device");
#if SERIAL_SAME
write_info_html_field(
"Baudrate",
String(baudrate_options[config.rx_baudrate]));
#else
write_info_html_field(
"RX Baudrate",
String(baudrate_options[config.rx_baudrate]));
write_info_html_field(
"TX Baudrate",
String(baudrate_options[config.tx_baudrate]));
#endif
write_info_html_field(
"RX Counter",
String(nmea_sentences_received));
write_info_html_field(
"TX Counter",
String(nmea_sentences_sent));
write_info_html_field(
"Voltage",
String(readvdd33() / 1000.0, 2) + String("V"));
write_info_html_field(
"Uptime",
get_uptime_display());
write_info_html_field(
"Device ID",
String(system_get_chip_id()));
write_info_html_section_end();
write_to_http_response_buffer(html_end);
send_http_response_buffer();
}
void write_form_html_field_start(const char *title, const char *tag) {
write_to_http_response_buffer("<");
write_to_http_response_buffer(tag);
write_to_http_response_buffer(" class="field">
write_to_http_response_buffer(title);
write_to_http_response_buffer("
}
void write_form_html_help(const char *help) {
if (help[0] != '\0') {
write_to_http_response_buffer("<p class="help">");
write_to_http_response_buffer(help);
write_to_http_response_buffer("");
}
}
void write_form_html_heading(String title) {
write_to_http_response_buffer("
");
write_to_http_response_buffer(title);
write_to_http_response_buffer("
");}
void write_form_html_field(const char *type, const char *name,
String value, const char *title,
const char *help, const char *attrs) {
write_form_html_field_start(title, "label");
write_form_html_help(help);
write_to_http_response_buffer("<input type="");
write_to_http_response_buffer(type);
write_to_http_response_buffer("" name="");
write_to_http_response_buffer(name);
write_to_http_response_buffer("" value="");
write_to_http_response_buffer(value);
write_to_http_response_buffer(""");
write_to_http_response_buffer(attrs);
write_to_http_response_buffer("/>");
}
void write_form_html_options_start(const char *title, const char *help) {
write_form_html_field_start(title, "div");
write_form_html_help(help);
write_to_http_response_buffer("<div class="optgroup">");
}
void write_form_html_options_item(const char *name, const char *value,
const char *title, const char *attrs,
bool checked) {
write_to_http_response_buffer("<label class="option">");
write_to_http_response_buffer("<input name="");
write_to_http_response_buffer(name);
write_to_http_response_buffer("" value="");
write_to_http_response_buffer(value);
write_to_http_response_buffer("" type="radio"");
if (checked) {
write_to_http_response_buffer(" checked");
}
write_to_http_response_buffer(attrs);
write_to_http_response_buffer("/>
");
write_to_http_response_buffer(title);
write_to_http_response_buffer("
}
void write_form_html_options_end() {
write_to_http_response_buffer("");
}
void write_form_html_select_start(const char *name, const char *title,
const char *help, const char *attrs) {
write_form_html_field_start(title, "label");
write_form_html_help(help);
write_to_http_response_buffer("<select name="");
write_to_http_response_buffer(name);
write_to_http_response_buffer(""");
write_to_http_response_buffer(attrs);
write_to_http_response_buffer(">");
}
void write_form_html_select_item(String value, String title, bool selected) {
write_to_http_response_buffer("<option value="");
write_to_http_response_buffer(value);
write_to_http_response_buffer(""");
if (selected) {
write_to_http_response_buffer(" selected");
}
write_to_http_response_buffer(">");
write_to_http_response_buffer(title);
write_to_http_response_buffer("");
}
void write_form_html_select_end() {
write_to_http_response_buffer("");
}
String ip_address_form_value(IPAddress addr) {
if (addr.isSet()) {
return addr.toString();
} else {
return "";
}
}
void write_form_html_baudrate_items(uint8_t selected_baudrate) {
for (int n = 1; n <= BAUDRATE_OPTION_COUNT; n ++) {
write_form_html_select_item(
String(n),
String(baudrate_options[n]),
selected_baudrate == n);
}
}
void send_config_form_response() {
/* Request handler for the config form page.
*/
if (captive_portal()) {return;}
if (http_server.method() == HTTP_POST) {
send_config_form_post_response();
return;
}
write_to_http_response_buffer(html_start);
write_to_http_response_buffer(
"<form method=\"post\"><h1>Configure</h1>");
write_form_html_heading("Network");
write_form_html_options_start("Wifi Mode", "");
write_form_html_options_item(
"1", "1", "Connect to existing access point", " required",
config.wifi_mode == WifiMode::station);
write_form_html_options_item(
"1", "2", "Create a new wifi access point", " required",
config.wifi_mode == WifiMode::access_point);
write_form_html_options_end();
write_form_html_field("text", "2", config.wifi_ssid, "Wifi SSID", "", " required");
write_form_html_field("text", "3", config.wifi_password, "Wifi password", "", " required");
write_form_html_field("text", "4", ip_address_form_value(config.static_ip_address), "IP Address", "Leave empty to get an address by DHCP.", "");
write_form_html_field("text", "5", config.mdns_hostname, "mDNS Hostname", "Leave empty to skip setting up mDNS.", "");
write_form_html_heading("Connection");
write_form_html_options_start("Transmit Mode", "");
write_form_html_options_item(
"6", "1", "Unicast", " required",
config.tx_mode == TransmitMode::unicast);
write_form_html_options_item(
"6", "2", "Multicast", " required",
config.tx_mode == TransmitMode::multicast);
write_form_html_options_item(
"6", "3", "Broadcast", " required",
config.tx_mode == TransmitMode::broadcast);
write_form_html_options_end();
write_form_html_field("text", "7", ip_address_form_value(config.tx_address), "UDP Transmit Address", "In broadcast mode, only the global broadcast address is used.<br>In unicast mode, this must be a valid unicast address.", "");
write_form_html_field("number", "8", String(config.tx_port), "UDP Transmit Port", "", " min=\"1\" max=\"65535\" required");
write_form_html_field("number", "9", String(config.rx_port), "UDP Receive Port", "", " min=\"1\" max=\"65535\" required");
write_form_html_heading("Device");
#if SERIAL_SAME
write_form_html_select_start("a", "Baudrate", "", " required");
write_form_html_baudrate_items(config.rx_baudrate);
write_form_html_select_end();
#else
write_form_html_select_start("a", "Receive Baudrate", "", " required");
write_form_html_baudrate_items(config.rx_baudrate);
write_form_html_select_end();
write_form_html_select_start("b", "Transmit Baudrate", "", " required");
write_form_html_baudrate_items(config.tx_baudrate);
write_form_html_select_end();
#endif
write_to_http_response_buffer(
"<button type=\"submit\">Save</button></form>");
write_to_http_response_buffer(html_end);
send_http_response_buffer();
}
void send_config_form_post_response() {
/* Request handler for the config form POST.
*/
Configuration new_config = config; // copy config
IPAddress addr;
uint16_t port;
WifiMode wifi_mode;
TransmitMode tx_mode;
uint8_t baudrate;
bool tx_config_changed = false;
bool rx_config_changed = false;
bool mdns_hostname = false;
bool tx_baudrate_changed = false;
bool rx_baudrate_changed = false;
for (uint8_t i = 0; i < http_server.args(); i++) {
String argname = http_server.argName(i);
const char *argname_str = argname.c_str();
if (argname_str[0] == '\0' || argname_str[1] != '\0') {
// Skip all param names that aren't a single character.
continue;
}
String argvalue = http_server.arg(i);
const char *argvalue_str = argvalue.c_str();
switch (argname_str[0]) {
case '1':
if (argvalue == "1") {
wifi_mode = WifiMode::station;
} else if (argvalue == "2") {
wifi_mode = WifiMode::access_point;
} else {
continue;
}
if (wifi_mode != new_config.wifi_mode) {
new_config.wifi_mode = wifi_mode;
is_network_config_changed = true;
}
break;
case '2':
strlcpy(new_config.wifi_ssid, argvalue_str, MAX_WIFI_SSID_SIZE);
if (strcmp(config.wifi_ssid, new_config.wifi_ssid) != 0) {
is_network_config_changed = true;
}
break;
case '3':
strlcpy(new_config.wifi_password, argvalue_str, MAX_WIFI_PASSWORD_SIZE);
if (strcmp(config.wifi_password, new_config.wifi_password) != 0) {
is_network_config_changed = true;
}
break;
case '4':
if (addr.fromString(argvalue)) {
if (addr != new_config.static_ip_address) {
new_config.static_ip_address = addr;
is_network_config_changed = true;
}
}
break;
case '5':
strlcpy(new_config.mdns_hostname, argvalue_str, MAX_MDNS_HOSTNAME_SIZE);
if (strcmp(config.mdns_hostname, new_config.mdns_hostname) != 0) {
mdns_hostname = true;
}
break;
case '6':
if (argvalue == "1") {
tx_mode = TransmitMode::unicast;
} else if (argvalue == "2") {
tx_mode = TransmitMode::multicast;
} else if (argvalue == "3") {
tx_mode = TransmitMode::broadcast;
} else {
continue;
}
if (tx_mode != new_config.tx_mode) {
new_config.tx_mode = tx_mode;
tx_config_changed = true;
}
break;
case '7':
if (addr.fromString(argvalue)) {
if (addr != new_config.tx_address) {
new_config.tx_address = addr;
tx_config_changed = true;
}
}
break;
case '8':
port = atoi(argvalue_str);
if (port == new_config.tx_port) {
continue;
}
if ((0 < port) && (port <= 65535)) {
new_config.tx_port = port;
tx_config_changed = true;
}
break;
case '9':
port = atoi(argvalue_str);
if (port == new_config.rx_port) {
continue;
}
if ((0 < port) && (port <= 65535)) {
new_config.rx_port = port;
rx_config_changed = true;
}
break;
case 'a':
baudrate = argvalue_str[0] - '0';
if ((1 <= baudrate) && (baudrate <= BAUDRATE_OPTION_COUNT)) {
if (baudrate != new_config.rx_baudrate) {
new_config.rx_baudrate = baudrate;
#if SERIAL_SAME
new_config.tx_baudrate = baudrate;
#endif
rx_baudrate_changed = true;
}
}
break;
#if !SERIAL_SAME
case 'b':
baudrate = argvalue_str[0] - '0';
if ((1 <= baudrate) && (baudrate <= BAUDRATE_OPTION_COUNT)) {
if (baudrate != new_config.tx_baudrate) {
new_config.tx_baudrate = baudrate;
tx_baudrate_changed = true;
}
}
break;
#endif
}
}
config = new_config;
store_config_to_eeprom(new_config);
if (tx_config_changed) {
update_tx_config();
}
if (rx_config_changed) {
update_rx_config();
}
if (mdns_hostname) {
update_mdns_hostname();
}
#if SERIAL_SAME
if (rx_baudrate_changed) {
update_rx_baudrate();
}
#else
if (tx_baudrate_changed) {
update_tx_baudrate();
}
if (rx_baudrate_changed) {
update_rx_baudrate();
}
#endif
http_server.sendHeader(
"Location",
http_server.uri(),
true);
http_server.send(302, "text/plain", "");
}
void nmea_log_page_response() {
/* Request handler for the NMEA log page.
*/
String body = html_start;
write_to_http_response_buffer(html_start);
write_to_http_response_buffer(html_log_content);
write_to_http_response_buffer(html_end);
send_http_response_buffer();
}
void send_js_log_script()
STATIC_FILE_REQUEST_HANDLER(JS_CONTENT_TYPE, js_log_script);
void send_css_style_response()
STATIC_FILE_REQUEST_HANDLER(CSS_CONTENT_TYPE, css_style);
void send_404_not_found_response() {
/* Request handler for undefined urls.
*/
if (captive_portal()) {return;}
String body = html_start;
body += "<h1>Page not found</h1>";
body += "<p>Happy sailing!</p>";
body += html_end;
http_server.send(404, "text/html", body);
}
/******************************
** EEPROM SETTINGS STORAGE **
******************************/
void load_config_from_eeprom(Configuration &new_config) {
/* Load config from persistent memory.
** The config is written to the passed instance.
*/
EEPROM.get(CONFIG_EEPROM_ADDRESS, new_config);
}
void store_config_to_eeprom(Configuration new_config) {
/* Store the given config to persistent memory.
*/
EEPROM.put(CONFIG_EEPROM_ADDRESS, new_config);
EEPROM.commit();
}
void fix_config() {
/* Update invalid config values to valid defaults.
*/
bool config_changed = false;
if (config.wifi_mode == 0 || config.wifi_mode > 2) {
config.wifi_mode = default_config.wifi_mode;
config_changed = true;
}
if (config.wifi_ssid[0] == '\0') {
strlcpy(config.wifi_ssid, default_config.wifi_ssid, MAX_WIFI_SSID_SIZE);
config_changed = true;
}
config.wifi_ssid[MAX_WIFI_SSID_SIZE - 1] = '\0';
if (config.wifi_password[0] == '\0') {
strlcpy(config.wifi_password, default_config.wifi_password, MAX_WIFI_PASSWORD_SIZE);
config_changed = true;
}
config.wifi_password[MAX_WIFI_PASSWORD_SIZE - 1] = '\0';
if (!config.static_ip_address.isSet()) {
config.static_ip_address = default_config.static_ip_address;
config_changed = true;
}
if (config.mdns_hostname[0] == '\0') {
strlcpy(config.mdns_hostname, default_config.mdns_hostname, MAX_MDNS_HOSTNAME_SIZE);
config_changed = true;
}
config.mdns_hostname[MAX_MDNS_HOSTNAME_SIZE - 1] = '\0';
if (config.tx_mode == 0 || config.tx_mode > 3) {
config.tx_mode = default_config.tx_mode;
config_changed = true;
}
if (!config.tx_address.isSet()) {
config.tx_address = default_config.tx_address;
config_changed = true;
}
if (!((0 < config.tx_port) && (config.tx_port <= 65535))) {
config.tx_port = default_config.tx_port;
config_changed = true;
}
if (!((0 < config.rx_port) && (config.rx_port <= 65535))) {
config.rx_port = default_config.rx_port;
config_changed = true;
}
if (config.tx_baudrate == 0 || config.tx_baudrate > BAUDRATE_OPTION_COUNT) {
config.tx_baudrate = default_config.tx_baudrate;
config_changed = true;
}
if (config.rx_baudrate == 0 || config.rx_baudrate > BAUDRATE_OPTION_COUNT) {
config.rx_baudrate = default_config.rx_baudrate;
config_changed = true;
}
if (config_changed) {
store_config_to_eeprom(config);
}
}
/************************
** UTILITY FUNCTIONS **
************************/
void update_mdns_hostname() {
/* Update the mDNS hostname,
** used then the config has changed.
*/
MDNS.setInstanceName(config.mdns_hostname);
// TODO this doen't work, how to change the mDNS hostname while running?
// https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266mDNS/src/ESP8266mDNS_Legacy.cpp
// MDNS.begin(config.mdns_hostname);
// MDNS.notifyAPChange();
}
void update_tx_config() {
/* Update the network transmit state,
** used then the config has changed.
/
if (config.tx_mode == TransmitMode::broadcast) {
if (config.tx_address == INADDR_NONE) {
// Special case; if the transmit address is set
// to 255.255.255.255, use this as broadcast address.
effective_tx_address = INADDR_NONE;
} else {
IPAddress gateway;
IPAddress subnet_mask;
if (effective_wifi_mode == WifiMode::access_point) {
gateway = WIFI_ACCESS_POINT_GATEWAY_IP;
subnet_mask = WIFI_ACCESS_POINT_SUBNET_IP;
} else {
gateway = WiFi.subnetMask();
subnet_mask = WiFi.gatewayIP();
}
effective_tx_address = IPAddress(
(~ uint32_t(subnet_mask))
| uint32_t(gateway));
}
} else {
effective_tx_address = config.tx_address;
}
}
void update_rx_config() {
/ Update the network receive state,
** used then the config has changed.
/
udp_server.stop();
udp_server.begin(config.rx_port);
}
void update_tx_baudrate() {
/ Update the transmit serial baudrate,
** used then the config has changed.
/
SERIAL_TX.flush();
SERIAL_TX.begin(baudrate_options[config.tx_baudrate]);
}
void update_rx_baudrate() {
/ Update the receive serial baudrate,
** used then the config has changed.
*/
SERIAL_RX.flush();
SERIAL_RX.begin(baudrate_options[config.rx_baudrate]);
}
IPAddress get_device_ip_address() {
/* Get the ip address of this device.
*/
if (effective_wifi_mode == WifiMode::access_point) {
return WiFi.softAPIP();
} else {
return WiFi.localIP();
}
}
IPAddress gateway_address(IPAddress addr) {
/* Get the gateway address based on an ip-address
** when connecting to an existing wifi network.
*/
return IPAddress(addr[0], addr[1], addr[2], 1);
}
IPAddress subnet_address(IPAddress addr) {
/* Get the subnet address-mask based on an ip-address
** when connecting to an existing wifi network.
*/
return IPAddress(255, 255, 255, 0);
}
unsigned long get_uptime_in_seconds() {
/* Get the current uptime in seconds.
*/
return millis() / 1000;
}
String get_uptime_display() {
/* Get the current uptime as a human-readable string.
*/
int seconds = get_uptime_in_seconds();
int minutes = seconds / 60;
int hours = minutes / 60;
int days = hours / 24;
seconds %= 60;
minutes %= 60;
hours %= 24;
char uptime_buffer[9];
snprintf(
uptime_buffer,
sizeof(uptime_buffer),
"%02d:%02d:%02d",
hours, minutes, seconds);
if (days == 0) {
return uptime_buffer;
} else if (days == 1) {
return "1 day, " + String(uptime_buffer);
} else {
return String(days) + " days, " + String(uptime_buffer);
}
}
void set_indicator_led_on() {
/* Set the indicator led on,
** if it isn't already so.
/
if (indicator_led_state == INDICATOR_LED_OFF) {
force_indicator_led_on();
}
}
void set_indicator_led_off() {
/ Set the indicator led off,
** if it isn't already so.
/
if (indicator_led_state == INDICATOR_LED_ON) {
force_indicator_led_off();
}
}
void force_indicator_led_on() {
/ Set the indicator led on,
** without checking the current state.
/
digitalWrite(INDICATOR_LED_PIN, INDICATOR_LED_ON);
indicator_led_state = INDICATOR_LED_ON;
}
void force_indicator_led_off() {
/ Set the indicator led off,
** without checking the current state.
/
digitalWrite(INDICATOR_LED_PIN, INDICATOR_LED_OFF);
indicator_led_state = INDICATOR_LED_OFF;
}
void toggle_indicator_led() {
/ Invert the indicator led state.
*/
if (indicator_led_state == INDICATOR_LED_ON) {
force_indicator_led_off();
} else {
force_indicator_led_on();
}
}
void long_indicator_blink() {
/* Perform a long-blink.
*/
force_indicator_led_on();
delay(1000);
force_indicator_led_off();
}
void update_indicator_slow_blink() {
/* Update the led state for slow-blinking.
*/
unsigned long time = millis() % 1000;
if (time < 500) {
set_indicator_led_on();
return;
}
set_indicator_led_off();
}
void update_indicator_double_blink() {
/* Update the led state for double-blinking.
*/
unsigned long time = millis() % 1000;
if (time < 100) {
set_indicator_led_on();
return;
} else if (time < 200) {
set_indicator_led_off();
return;
} else if (time < 300) {
set_indicator_led_on();
return;
}
set_indicator_led_off();
}
bool blink_while_pressing_mode_button() {
/* Return True if pressed longer than the threshold.
*/
unsigned long start_time = millis();
while (digitalRead(BOOT_MODE_BUTTON_PIN) == LOW) {
toggle_indicator_led();
delay(50);
if ((millis() - start_time) > RESET_CONFIG_THRESHOLD) {
set_indicator_led_off();
return true;
}
}
set_indicator_led_off();
return false;
}
void blink_while_connecting_wifi() {
/* Return when wifi is connected.
*/
while (WiFi.status() != WL_CONNECTED) {
toggle_indicator_led();
delay(500);
DEBUG_PRINT(".");
}
set_indicator_led_on();
DEBUG_PRINTLN("");
}`
please post a working sketch (for nodemcu esp8266). I really need to connect nmea 0183 to wifi |
The ssid says ESP-XXXXX and the password is unknown. I used a new ESP8266 chip, but everything remains as it was at the beginning. Changing the network name and password is not possible. Use Arduino IDE2.1 It's a shame I would have liked to try this thing out. greeting
The text was updated successfully, but these errors were encountered: