NodeMCU sketch is crashing due to “WiFi.localIP(); ”












0















My code was previously working, but today when I ran it it began crashing as soon as it runs on the device. I noticed that the serial monitor printed IP Address: right before the crash, so that led me to play around and isolate the line WiFi.localIP(); as the culprit for the crash. If I remove it, the sketch runs. If I relocate it before or after lines which print to the serial monitor, I will see those printed statements before the error.



Error Trace:



.
IP Address:
Exception (28):
epc1=0x4020a96c epc2=0x00000000 epc3=0x00000000 excvaddr=0x00004298 depc=0x00000000

ctx: cont
sp: 3ffffd50 end: 3fffffd0 offset: 01a0

>>>stack>>>
3ffffef0: 20676e69 6f686353 fe006c6f feefeffe
3fffff00: 69646f43 4e40676e 00545845 00000000
3fffff10: 40104ab2 000032f3 00000100 00000003
3fffff20: 3ffe8a98 00000000 3ffef798 00000003
3fffff30: 3ffe8a98 3ffef728 3ffef798 40206a60
3fffff40: 3ffe9060 3ffef798 3ffef728 40206949
3fffff50: 00004298 3fffff80 3ffef728 40206cf0
3fffff60: c001a8c0 00ffffff 3ffef798 40206cd8
3fffff70: 3fffdad0 3ffef728 3ffef798 40202eaa
3fffff80: 40208160 c001a8c0 feefeffe feefeffe
3fffff90: feefeffe feefeffe feefeffe feefeffe
3fffffa0: feefeffe feefeffe feefeffe 3ffef858
3fffffb0: 3fffdad0 00000000 3ffef852 4020781c
3fffffc0: feefeffe feefeffe 3ffe863c 40100739
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(1,6)


ets Jan 8 2013,rst cause:4, boot mode:(1,6)

wdt reset


Portion of Sketch:



 #include <ESP8266WiFi.h>
#include <WebSocketsClient.h>
#include <ArduinoJson.h>
#include <EEPROM.h>

// Initialize pins
int redpin = D0;
int greenpin = D2;
int bluepin = D4;

//// Connecting to the internet
const char* ssid = "********";
const char* password = "********";

// Setting up the websocket client
WebSocketsClient webSocket;

// Set up the WiFi client;
WiFiClient client;

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);

pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);


delay(10);
WiFi.begin(ssid, password);
while(WiFi.status()!= WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.print("IP Address: ");
Serial.print(WiFi.localIP() + "n");
Serial.print(WiFi.macAddress() + "n");
}


I expect the program to run without error as it was previously doing that and I did not change the code at all. I do not technically need the IP address for my sketch to function, but I am quite confused as to why it is suddenly raising an error and would like to understand.










share|improve this question























  • I doubt that IPAddress class supports concatenation with a c-string.

    – gre_gor
    Jan 18 at 16:02
















0















My code was previously working, but today when I ran it it began crashing as soon as it runs on the device. I noticed that the serial monitor printed IP Address: right before the crash, so that led me to play around and isolate the line WiFi.localIP(); as the culprit for the crash. If I remove it, the sketch runs. If I relocate it before or after lines which print to the serial monitor, I will see those printed statements before the error.



Error Trace:



.
IP Address:
Exception (28):
epc1=0x4020a96c epc2=0x00000000 epc3=0x00000000 excvaddr=0x00004298 depc=0x00000000

ctx: cont
sp: 3ffffd50 end: 3fffffd0 offset: 01a0

>>>stack>>>
3ffffef0: 20676e69 6f686353 fe006c6f feefeffe
3fffff00: 69646f43 4e40676e 00545845 00000000
3fffff10: 40104ab2 000032f3 00000100 00000003
3fffff20: 3ffe8a98 00000000 3ffef798 00000003
3fffff30: 3ffe8a98 3ffef728 3ffef798 40206a60
3fffff40: 3ffe9060 3ffef798 3ffef728 40206949
3fffff50: 00004298 3fffff80 3ffef728 40206cf0
3fffff60: c001a8c0 00ffffff 3ffef798 40206cd8
3fffff70: 3fffdad0 3ffef728 3ffef798 40202eaa
3fffff80: 40208160 c001a8c0 feefeffe feefeffe
3fffff90: feefeffe feefeffe feefeffe feefeffe
3fffffa0: feefeffe feefeffe feefeffe 3ffef858
3fffffb0: 3fffdad0 00000000 3ffef852 4020781c
3fffffc0: feefeffe feefeffe 3ffe863c 40100739
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(1,6)


ets Jan 8 2013,rst cause:4, boot mode:(1,6)

wdt reset


Portion of Sketch:



 #include <ESP8266WiFi.h>
#include <WebSocketsClient.h>
#include <ArduinoJson.h>
#include <EEPROM.h>

// Initialize pins
int redpin = D0;
int greenpin = D2;
int bluepin = D4;

//// Connecting to the internet
const char* ssid = "********";
const char* password = "********";

// Setting up the websocket client
WebSocketsClient webSocket;

// Set up the WiFi client;
WiFiClient client;

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);

pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);


delay(10);
WiFi.begin(ssid, password);
while(WiFi.status()!= WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.print("IP Address: ");
Serial.print(WiFi.localIP() + "n");
Serial.print(WiFi.macAddress() + "n");
}


I expect the program to run without error as it was previously doing that and I did not change the code at all. I do not technically need the IP address for my sketch to function, but I am quite confused as to why it is suddenly raising an error and would like to understand.










share|improve this question























  • I doubt that IPAddress class supports concatenation with a c-string.

    – gre_gor
    Jan 18 at 16:02














0












0








0








My code was previously working, but today when I ran it it began crashing as soon as it runs on the device. I noticed that the serial monitor printed IP Address: right before the crash, so that led me to play around and isolate the line WiFi.localIP(); as the culprit for the crash. If I remove it, the sketch runs. If I relocate it before or after lines which print to the serial monitor, I will see those printed statements before the error.



Error Trace:



.
IP Address:
Exception (28):
epc1=0x4020a96c epc2=0x00000000 epc3=0x00000000 excvaddr=0x00004298 depc=0x00000000

ctx: cont
sp: 3ffffd50 end: 3fffffd0 offset: 01a0

>>>stack>>>
3ffffef0: 20676e69 6f686353 fe006c6f feefeffe
3fffff00: 69646f43 4e40676e 00545845 00000000
3fffff10: 40104ab2 000032f3 00000100 00000003
3fffff20: 3ffe8a98 00000000 3ffef798 00000003
3fffff30: 3ffe8a98 3ffef728 3ffef798 40206a60
3fffff40: 3ffe9060 3ffef798 3ffef728 40206949
3fffff50: 00004298 3fffff80 3ffef728 40206cf0
3fffff60: c001a8c0 00ffffff 3ffef798 40206cd8
3fffff70: 3fffdad0 3ffef728 3ffef798 40202eaa
3fffff80: 40208160 c001a8c0 feefeffe feefeffe
3fffff90: feefeffe feefeffe feefeffe feefeffe
3fffffa0: feefeffe feefeffe feefeffe 3ffef858
3fffffb0: 3fffdad0 00000000 3ffef852 4020781c
3fffffc0: feefeffe feefeffe 3ffe863c 40100739
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(1,6)


ets Jan 8 2013,rst cause:4, boot mode:(1,6)

wdt reset


Portion of Sketch:



 #include <ESP8266WiFi.h>
#include <WebSocketsClient.h>
#include <ArduinoJson.h>
#include <EEPROM.h>

// Initialize pins
int redpin = D0;
int greenpin = D2;
int bluepin = D4;

//// Connecting to the internet
const char* ssid = "********";
const char* password = "********";

// Setting up the websocket client
WebSocketsClient webSocket;

// Set up the WiFi client;
WiFiClient client;

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);

pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);


delay(10);
WiFi.begin(ssid, password);
while(WiFi.status()!= WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.print("IP Address: ");
Serial.print(WiFi.localIP() + "n");
Serial.print(WiFi.macAddress() + "n");
}


I expect the program to run without error as it was previously doing that and I did not change the code at all. I do not technically need the IP address for my sketch to function, but I am quite confused as to why it is suddenly raising an error and would like to understand.










share|improve this question














My code was previously working, but today when I ran it it began crashing as soon as it runs on the device. I noticed that the serial monitor printed IP Address: right before the crash, so that led me to play around and isolate the line WiFi.localIP(); as the culprit for the crash. If I remove it, the sketch runs. If I relocate it before or after lines which print to the serial monitor, I will see those printed statements before the error.



Error Trace:



.
IP Address:
Exception (28):
epc1=0x4020a96c epc2=0x00000000 epc3=0x00000000 excvaddr=0x00004298 depc=0x00000000

ctx: cont
sp: 3ffffd50 end: 3fffffd0 offset: 01a0

>>>stack>>>
3ffffef0: 20676e69 6f686353 fe006c6f feefeffe
3fffff00: 69646f43 4e40676e 00545845 00000000
3fffff10: 40104ab2 000032f3 00000100 00000003
3fffff20: 3ffe8a98 00000000 3ffef798 00000003
3fffff30: 3ffe8a98 3ffef728 3ffef798 40206a60
3fffff40: 3ffe9060 3ffef798 3ffef728 40206949
3fffff50: 00004298 3fffff80 3ffef728 40206cf0
3fffff60: c001a8c0 00ffffff 3ffef798 40206cd8
3fffff70: 3fffdad0 3ffef728 3ffef798 40202eaa
3fffff80: 40208160 c001a8c0 feefeffe feefeffe
3fffff90: feefeffe feefeffe feefeffe feefeffe
3fffffa0: feefeffe feefeffe feefeffe 3ffef858
3fffffb0: 3fffdad0 00000000 3ffef852 4020781c
3fffffc0: feefeffe feefeffe 3ffe863c 40100739
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(1,6)


ets Jan 8 2013,rst cause:4, boot mode:(1,6)

wdt reset


Portion of Sketch:



 #include <ESP8266WiFi.h>
#include <WebSocketsClient.h>
#include <ArduinoJson.h>
#include <EEPROM.h>

// Initialize pins
int redpin = D0;
int greenpin = D2;
int bluepin = D4;

//// Connecting to the internet
const char* ssid = "********";
const char* password = "********";

// Setting up the websocket client
WebSocketsClient webSocket;

// Set up the WiFi client;
WiFiClient client;

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);

pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);


delay(10);
WiFi.begin(ssid, password);
while(WiFi.status()!= WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.print("IP Address: ");
Serial.print(WiFi.localIP() + "n");
Serial.print(WiFi.macAddress() + "n");
}


I expect the program to run without error as it was previously doing that and I did not change the code at all. I do not technically need the IP address for my sketch to function, but I am quite confused as to why it is suddenly raising an error and would like to understand.







c++ arduino esp8266 nodemcu arduino-esp8266






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 18 at 8:24









emijuneemijune

859




859













  • I doubt that IPAddress class supports concatenation with a c-string.

    – gre_gor
    Jan 18 at 16:02



















  • I doubt that IPAddress class supports concatenation with a c-string.

    – gre_gor
    Jan 18 at 16:02

















I doubt that IPAddress class supports concatenation with a c-string.

– gre_gor
Jan 18 at 16:02





I doubt that IPAddress class supports concatenation with a c-string.

– gre_gor
Jan 18 at 16:02












1 Answer
1






active

oldest

votes


















0














WiFi.localIP() returns an IPAddress, not a String (see its reference page). You need to turn it into a String before you concatenate anything to it.



So instead of:



Serial.print(WiFi.localIP() + "n");


You need



Serial.print(String(WiFi.localIP()) + "n");


Even better, use String.println() and avoid the concatenation and String object construction:



Serial.println(WiFi.localIP());


This works because there are versions of the print() and println() methods which take an IPAddress as an argument and know how to convert it into text.



Similarly, WiFi.macAddress() fills a 6 byte array holding the MAC address of the WiFi interface and does return not a String (see its reference page). You can't easily construct a String from it and the print methods won't know how to handle it.



So instead of:



Serial.print(WiFi.macAddress() + "n");


You'll need to do something like:



byte mac_address[6];

WiFi.macAddress(mac_address);
Serial.printf("%02x:%02x:%02x:%02x:%02x:%02xn",
mac_address[0], mac_address[1], mac_address[2],
mac_address[3], mac_address[4], mac_address[5]);





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54250050%2fnodemcu-sketch-is-crashing-due-to-wifi-localip%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    WiFi.localIP() returns an IPAddress, not a String (see its reference page). You need to turn it into a String before you concatenate anything to it.



    So instead of:



    Serial.print(WiFi.localIP() + "n");


    You need



    Serial.print(String(WiFi.localIP()) + "n");


    Even better, use String.println() and avoid the concatenation and String object construction:



    Serial.println(WiFi.localIP());


    This works because there are versions of the print() and println() methods which take an IPAddress as an argument and know how to convert it into text.



    Similarly, WiFi.macAddress() fills a 6 byte array holding the MAC address of the WiFi interface and does return not a String (see its reference page). You can't easily construct a String from it and the print methods won't know how to handle it.



    So instead of:



    Serial.print(WiFi.macAddress() + "n");


    You'll need to do something like:



    byte mac_address[6];

    WiFi.macAddress(mac_address);
    Serial.printf("%02x:%02x:%02x:%02x:%02x:%02xn",
    mac_address[0], mac_address[1], mac_address[2],
    mac_address[3], mac_address[4], mac_address[5]);





    share|improve this answer






























      0














      WiFi.localIP() returns an IPAddress, not a String (see its reference page). You need to turn it into a String before you concatenate anything to it.



      So instead of:



      Serial.print(WiFi.localIP() + "n");


      You need



      Serial.print(String(WiFi.localIP()) + "n");


      Even better, use String.println() and avoid the concatenation and String object construction:



      Serial.println(WiFi.localIP());


      This works because there are versions of the print() and println() methods which take an IPAddress as an argument and know how to convert it into text.



      Similarly, WiFi.macAddress() fills a 6 byte array holding the MAC address of the WiFi interface and does return not a String (see its reference page). You can't easily construct a String from it and the print methods won't know how to handle it.



      So instead of:



      Serial.print(WiFi.macAddress() + "n");


      You'll need to do something like:



      byte mac_address[6];

      WiFi.macAddress(mac_address);
      Serial.printf("%02x:%02x:%02x:%02x:%02x:%02xn",
      mac_address[0], mac_address[1], mac_address[2],
      mac_address[3], mac_address[4], mac_address[5]);





      share|improve this answer




























        0












        0








        0







        WiFi.localIP() returns an IPAddress, not a String (see its reference page). You need to turn it into a String before you concatenate anything to it.



        So instead of:



        Serial.print(WiFi.localIP() + "n");


        You need



        Serial.print(String(WiFi.localIP()) + "n");


        Even better, use String.println() and avoid the concatenation and String object construction:



        Serial.println(WiFi.localIP());


        This works because there are versions of the print() and println() methods which take an IPAddress as an argument and know how to convert it into text.



        Similarly, WiFi.macAddress() fills a 6 byte array holding the MAC address of the WiFi interface and does return not a String (see its reference page). You can't easily construct a String from it and the print methods won't know how to handle it.



        So instead of:



        Serial.print(WiFi.macAddress() + "n");


        You'll need to do something like:



        byte mac_address[6];

        WiFi.macAddress(mac_address);
        Serial.printf("%02x:%02x:%02x:%02x:%02x:%02xn",
        mac_address[0], mac_address[1], mac_address[2],
        mac_address[3], mac_address[4], mac_address[5]);





        share|improve this answer















        WiFi.localIP() returns an IPAddress, not a String (see its reference page). You need to turn it into a String before you concatenate anything to it.



        So instead of:



        Serial.print(WiFi.localIP() + "n");


        You need



        Serial.print(String(WiFi.localIP()) + "n");


        Even better, use String.println() and avoid the concatenation and String object construction:



        Serial.println(WiFi.localIP());


        This works because there are versions of the print() and println() methods which take an IPAddress as an argument and know how to convert it into text.



        Similarly, WiFi.macAddress() fills a 6 byte array holding the MAC address of the WiFi interface and does return not a String (see its reference page). You can't easily construct a String from it and the print methods won't know how to handle it.



        So instead of:



        Serial.print(WiFi.macAddress() + "n");


        You'll need to do something like:



        byte mac_address[6];

        WiFi.macAddress(mac_address);
        Serial.printf("%02x:%02x:%02x:%02x:%02x:%02xn",
        mac_address[0], mac_address[1], mac_address[2],
        mac_address[3], mac_address[4], mac_address[5]);






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 18 at 17:57

























        answered Jan 18 at 16:12









        John RomkeyJohn Romkey

        78956




        78956






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54250050%2fnodemcu-sketch-is-crashing-due-to-wifi-localip%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Homophylophilia

            Updating UILabel text programmatically using a function

            Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage