• Hi @Gordon and friends,
    I've a Toy that has Espruino Pico with ESP8266 WiFi module. I could connect to the WiFi by hard coding the SSID & PWD. But i would like to present this Toy to a few of my friends. How would i make sure the WiFi connection can be done more user friendly way ? That means my friends can't hard code the credentials. Please suggest me how can this be done? Thank you!

  • Hi, What I'd suggest is that soon after power-on you detect if the button is pressed, and if it is you put the WiFi module into access point mode with wifi.createAP("ESP123","HelloWorld",5,"w­pa2_psk",function() { now connected ... })

    You can then create a webserver which serves up a page where the wifi credentials are entered - and you can store those credentials using require("FlashEEPROM").write.

    Then, when you boot up without the button pressed, read credentials using require("FlashEEPROM").read and connect to that WiFi network.

    Either that, or if this is a toy and it needs controlling (but not an internet connection) you could just always make it create its own access point rather than connecting to another network?

  • Got it! Thank you so much :)
    What if the device is stolen, isn't a security concern if we store these in the device?

  • oh.. i see an 'erase' method in the 'FlashEEPROM' object. I think, i will delete the content once used.

  • You could just store the Wifi credentials in RAM so that they are lost on power-off if that is a real concern? However I imagine the vast majority of consumer electronics will store your WiFi details in plain text :)

  • You are right. We should be careful :)
    I think that's the reason a few consumer electronics generate secret keys in their mobile/desktop app which can be used for logging into their devices.

    I could run a HTTP server, but is it possible for me to run a HTTPS server?

  • I don't think it is possible at the moment.

    However, if you're connecting over a WEP access point the ESP8266 has created, that is itself encrypted so I think the chances of snooping are pretty much zero.

  • Sure. Thank you! I'm giving a try now.

  • @Gordon I'm able to store the credentials in the FlashEEPROM, but i lose the data as i reboot. I can get the expected value from the left side panel but not in my code that is on the right side of IDE. Is it non-volatile or volatile memory?

  • FlashEEPROM should definitely be non-volatile. Just try some simple code:

    var f = new (require("FlashEEPROM"))();
    f.write(0, "Hello");
    

    then reboot and try to read it:

    var f = new (require("FlashEEPROM"))();
    console.log(E.toString(f.read(0)))
    
  • Thank you! @Gordon

    I had the following defensive code that caused the issue. It does not work because 'f.read(0) ' is a typed array and condition failed to assign a value.

    let apSSID = f.read(0) && E.toString(f.read(0))
    

    This works perfectly fine

    let apSSID = typeof f.read(0) !== 'undefined' ? E.toString(f.read(0)) : '';
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to connect to WiFi without hardcoding the credentials in Espruino Pico?

Posted by Avatar for sureshkm @sureshkm

Actions