I think i might be doing this wrong but i want to know for sure. below I create a char array[] then add an ip address to it,
char T1_IP[16];
char T2_IP[16];
char T3_IP[16];
char T4_IP[16];
char TM1_IP[16];
char TM2_IP[16];
//////////////////////////////////////////////
void recvPacket() {
int packetSize = Udp.parsePacket();
if (packetSize) {
int len = Udp.read(incomingPacket, 3000);
char verifyStart[7];
char verifyEnd[7];
//char _data[5];
strncpy (verifyStart, (char*)incomingPacket, 6 );//6 bytes
strncpy (verifyEnd, (char *)incomingPacket + len - 6 , 6 );//6 bytes
verifyStart[6] = '\0'; //null terminate
verifyEnd[6] = '\0'; //null terminate
if (strcmp(verifyStart, "T1PAIR") == 0 && strcmp(verifyEnd, "1TAPVU") == 0) {
char new_ip[15];
Udp.remoteIP().toString().toCharArray(new_ip, 15);
if (strcmp(_EEPROM.T1_IP, new_ip) != 0) {
Udp.remoteIP().toString().toCharArray(_EEPROM.T1_IP, 15);
if (debugPairing) {
Serial.println("T1 Paired!");
Serial.println(_EEPROM.T1_IP);
}
_writeEEPROM();
} else {
if (debugPairing) {
Serial.println("No need to update temp 1 address");
}
}
}
in the if statement below the char arrays[] you can see how i convert string to array but i dont add a null terminator. is this okay? .tochararray .toString dont mention terminating the string but i think say expect a terminator? will my code above cause issues?
jremington:
As far as I know, all of the string routines expect a null terminator. It would be silly to leave them out.
Who knows what will happen if you (in-advisedly) mix Strings with C-strings?
well im having weird issues. such as a serial print statement garbled. im trying to find the error in my code and this part to me stands out the most. Please explain what will happen if i mix c string with Strings. the program worked well until memory usage was a concern. now it seems like i'm having overflows.
Also if udp.remoteIP() returns 4 bytes. would i only need to initialize the array with 5 bytes? does it makes sense to use array[16]?
TheMemberFormerlyKnownAsAWOL:
Can we be clear - are you trying to make an IP address , or a printable representation of an IP address?
I made a discovery method to find my modules on the network. i send udp messages to every address by looping through the last octet start at 1 ending at 255.
A client will receive a message and attempt to store the IPAddress in the eeprom so that it can be used with Udp.BeginPacket(_EEPROM.IPADDRESS, PORT);.
So i am trying to create an Ipaddress that can be handed over to Udp.beginPacket() and be saved in the eeprom. I rely on Udp.remoteIp() to retrieve the address from the senders to be stored in the EEPROM.
Would this make more sense to create an IPAddress object and populate it with udp.remoteip()? thne i can use sprintf to send it to "char _EEPROM.masert_ip[15];?? char array[] is a string? not a String?
IPAddress ip = Udp.remoteIP();
sprintf(_EEPROM.masterIP, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
Instead of all the String and char array conversion, you may find it easier to work with the IP address object and write the four bytes ip[0], ip[1], ip[2], ip[3] into four bytes of the eeprom.
You do not store the address object, just the underlying bytes,
You can certainly recreate the ip address object from the four bytes when you read them.
cattledog:
Instead of all the String and char array conversion, you may find it easier to work with the IP address object and write the four bytes ip[0], ip[1], ip[2], ip[3] into four bytes of the eeprom.
You do not store the address object, just the underlying bytes,
You can certainly recreate the ip address object from the four bytes when you read them.
i didnt think about that. sprintf() should be okay right?
IPAddress ip = Udp.remoteIP();
sprintf(_EEPROM.masterIP, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
i dont know how to store the 4 bytes. the only way i can thing of is a char array for each byte and then save the eeprom. i store the whole struct in eeprom dont know how to store a single byte like you describe,
My esp8266 is crashing and i have not been able to figure out why. this is my decoded stack trace,
Exception 0: Illegal instruction
PC: 0x465569cf
EXCVADDR: 0x00000000
Decoding stack results
0x40100eaf: free(void*) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\umm_malloc\umm_malloc.cpp line 398
0x40101142: calloc(size_t, size_t) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\umm_malloc\umm_malloc.cpp line 908
0x402299d2: new_linkoutput at glue-lwip/lwip-git.c line 260
0x40229df0: ethernet_output at netif/ethernet.c line 312
0x4023182d: etharp_output_LWIP2 at core/ipv4/etharp.c line 896
0x402330fc: ip4_output_if_opt_src at core/ipv4/ip4.c line 1764
0x40100ee4: malloc(size_t) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\umm_malloc\umm_malloc.cpp line 552
0x40233bf0: mem_malloc at core/mem.c line 210
0x40233144: ip4_output_if_opt at core/ipv4/ip4.c line 1577
0x40231a85: igmp_send at core/ipv4/igmp.c line 797
0x40100ee4: malloc(size_t) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\umm_malloc\umm_malloc.cpp line 552
0x40100c2b: umm_free_core(void*) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\umm_malloc\umm_malloc.cpp line 351
0x40231e2c: igmp_tmr at core/ipv4/igmp.c line 658
0x4022af50: lwip_cyclic_timer at core/timeouts.c line 233
0x4022af60: lwip_cyclic_timer at core/timeouts.c line 243
0x40229ea9: memp_free at core/memp.c line 447
0x4022b0f8: sys_check_timeouts at core/timeouts.c line 390
0x4021dd80: loop_task(ETSEvent*) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 205
0x4021b7a0: _GLOBAL__sub_D__ZN14HardwareSerialC2Ei() at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/HardwareSerial.h line 72
0x4021c9e8: _GLOBAL__sub_D__ZN12UpdaterClassC2Ev() at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\Updater.cpp line 579
0x4021dc14: _GLOBAL__sub_D__ZN6StringC2EPKc() at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\WString.cpp line 856
0x40229745: glue2esp_linkoutput at glue-esp/lwip-esp.c line 301
0x40100ee4: malloc(size_t) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\umm_malloc\umm_malloc.cpp line 552
0x402299d2: new_linkoutput at glue-lwip/lwip-git.c line 260
0x40229df0: ethernet_output at netif/ethernet.c line 312
0x402312a4: etharp_raw at core/ipv4/etharp.c line 1165
0x40231ac6: igmp_delaying_member at core/ipv4/igmp.c line 698
0x4023149a: etharp_request at core/ipv4/etharp.c line 1202
0x40231b23: igmp_report_groups at core/ipv4/igmp.c line 205
0x4010039c: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 177
0x40214ed0: Adafruit_GFX::drawChar(short, short, unsigned char, unsigned short, unsigned short, unsigned char, unsigned char) at C:\Users\Laptop\Documents\Arduino\libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp line 1105
0x4010039c: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 177
0x40229bc5: esp2glue_netif_set_up1down0 at glue-lwip/lwip-git.c line 485
0x4010039c: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 177
0x4022dbd8: netif_set_addr_LWIP2 at core/netif.c line 717
0x4010039c: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 177
0x4010039c: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 177
0x4010039c: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 177
0x4010039c: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 177
0x4020faed: esp8266webserver::ESP8266WebServerTemplate ::handleClient() at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h line 312
0x4020faed: esp8266webserver::ESP8266WebServerTemplate ::handleClient() at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h line 312
0x40100720: millis() at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_wiring.cpp line 188
0x4020fbec: pairMe() at C:\Users\Laptop\Documents\Arduino\esp_scan_master/esp_scan_master.ino line 184
0x40210ff0: ESP8266WiFiSTAClass::status() at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 634
0x4020fd3e: loop() at C:\Users\Laptop\Documents\Arduino\esp_scan_master/esp_scan_master.ino line 163
0x40220130: std::_Function_base::_Base_manager ::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) at c:\users\laptop\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2/functional line 1934
0x4022011c: std::_Function_handler ::_M_invoke(std::_Any_data const&) at c:\users\laptop\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2/functional line 2069
0x4010039c: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 177
0x401003bd: esp_schedule() at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 125
0x4021df2d: loop_wrapper() at C:\Users\Laptop\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 199
also the crashes happen without processing incoming packets.