-
• #2
It's because the line
require("ESP8266WiFi_0v25").connect
is being executed when the code is uploaded to the board, rather than aftersave()
. To fix it, just put that code into an function calledonInit
:var soc; var wifi; function onInit() { Serial3.setup(115200, { rx: D9, tx : D8 }); wifi = require("ESP8266WiFi_0v25").connect(Serial3, function(err) { if (err) {digitalWrite(LED4,1);throw err;} //wifi.at.debug(); console.log("Connecting to WiFi"); wifi.connect("Espruino",'freeWifi', function(err) { if (err) throw err; console.log("Connected"); require("net").createServer(function(c){ console.log("incomming connection"); c.on('data', onDataCallback); c.on('close', function(){ console.log("bye"); }); soc = c; }).listen(8080); wifi.getIP(function(err,ip){ if(err === null){ console.log(ip); serverIP = ip; digitalWrite(LED2, 1); } }); }); }); } function onDataCallback(data){ digitalWrite(LED1, !digitalRead(LED1)); console.log("Server received: " + data); if(data !== undefined){ if(data.length >= 6 && data.substr(0, 3).toLowerCase() == "led"){ switch(data.charAt(3)){ case '1':digitalWrite(LED1, data.charAt(5));break; case '2':digitalWrite(LED2, data.charAt(5));break; case '3':digitalWrite(LED3, data.charAt(5));break; case '4':digitalWrite(LED4, data.charAt(5));break; } } soc.write("Response: " + data); if(data.substr(0,4) == "exit") soc.end(); } }
-
• #3
... also, I wouldn't put
save()
at the end of your code when uploading, as it means your uploaded code is saved with echo off, which makes it hard to debug. Just do it manually on the left-hand side after you've uploaded the code. -
• #4
Awesome, it fixed the problem. Thanks a lot.
Hi, I'm trying to create server on ESP8266 and when I run code locally with USB cable connected it works fine, but when I save code to flash I get "Not connected to the internet" error.
I'm not sure what I do wrong or why is the internet connection required, because I'm not communicating with it. Can someone please help me?
I use STM32F4Discovery with 1.80.1 Espruino and MOD-WIFI-ESP8266 with 0.25 firmware version.
Code is below