Espruino WiFi - Error starting in AP mode

Posted on
  • Hey all,

    First off I'll briefly explain what I want to do: I am looking to use the Espruino WiFi as a way to allow the tablet, which is mounted in my car, to control certain aspects of the vehicle. As an example, let's assume I want to be able to start the car's engine with my voice. I would speak a voice command to my tablet (of course this is custom software), which would then send a command to the Espruino WiFi (presumably via WiFi) and the Espruino WiFi board would then supply power to a relay which would then start the car. I would also want to be able to use my mobile phone to interact with the Espruino WiFi.

    The above scenario is all very conceptual, and it has its shortcomings, but it's along the lines of what I want to accomplish.

    Now, onto the problem: I am using a relatively simple snippet of code I found here at Espruino.com, just to create an access point:

    function onInit() {
      var wifi = require("EspruinoWiFi");
      
      console.log("Creating AP...");
      
      wifi.startAP('EspruinoAP', { password: '0123456789', authMode: 'wpa2' }, function(err) {
        if (err) console.log("Error creating AP:", err);
      });
    }
    
    onInit();
    

    Each time I reset the Espruino WiFi, I get the following error:

    Error creating AP: CWMODE failed: AT+CWMODE=2

    Has anyone had this error and have you had success fixing it?

  • @bosscube, could you elaborate on:

    Each time I reset the Espruino WiFi,...

    Could you list the step you perform to get there?

    Good practice is to put the onInti() into a setTimeout() in order to let the upload complete in it's own thread-share.

    setTimeout(onInit,1000);
    

    If you consider saving the code (with save()), remove this setTimeout(onInit,1000);, upload the code again, and then perform the save() in the console.

  • Sorry, I should've articulated a bit better. I meant every time I attempt to run that code, it fails to create the AP. I have the Espruino IDE set to save the code each time it's sent to the board.

    I tried a 1-second timeout and it still failed. The good news is, I tried a 5-second timeout and it worked! I guess I will play around with the timeouts a bit more and see what works best. Thanks a lot for the help - glad it was an easy fix.

    Also, if this isn't mentioned in the documentation, it probably should be. If it is, whoops!

  • Glad it's working for you...

    I never use the setting for save on upload... lat but not least this - in my biased view -was an afterthought to appease the Arduino tooling behavior... because it also runs down the flash EPROM... (of course, 10K writes or what ever it guarantees is a lot... but not that much for my micro-incremental dev style). Only once in a while and when I'm done I go for the save().

  • That's a strange one - are you using up to date firmware (1v94?) I just tried uploading your code exactly as it was and it appears to work fine for me?

    *Could it be that you have onInit() at the end of your code and you have turned save on send on in the IDE options?* That causes the error you report for me.

    If so, what you're doing is calling onInit twice, in quick succession - and that's what is tripping it up.

    What you're suggesting to do with the rest of your project sounds great! I'd love to hear how you get on.

    Only thing I'd say is be careful when powering Espruino WiFi from your car. Personally I'd use a car USB charger and power it using Micro USB. Espruino WiFi doesn't have same USB power circuitry other boards do, so you need to be really careful when powering it from an external voltage if you're also going to plug it into your computer via USB. Powering it from Micro USB is a really nice easy way to get around that :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Espruino WiFi - Error starting in AP mode

Posted by Avatar for bosscube @bosscube

Actions