-
@Ollie, thanks. Now i'm struggling on how i can invoke a function (startServer) just after the wifi.connected. How can i use the callback function of wifi.connected if the wifi parameters are saved outside the lines of code but they was stored before with wifi.save()? How can i callback they? Sorry if it can be a silly question, i'm starting out now with programming.
-
Thanks @allObjects, can you explain me what you mean by "sequencer and initializer" (or point me where I can read something about its) I'm a total newbie on JavaScript (trying to learn) and on programming in general (coming from the electronic field).
Saluti.
Marco -
@tve, i've tried many times but wifi.save() don't save the wifi paramenters. If power down/up again and i try wifi.getIP() i receive an "wifi is not defined". If i put a save() inside the code and do the power cycle again doing a wifi.getIP() i have a response.
Maybe because at the moment im using an old version? (1v84.tve_master_588d193).
I'll try with the latest and i let you know.
Anyway thanks. -
@tve. I tried to put
var wifi = require("Wifi"); wifi.connect("myssid", {password:"mypass"}, function(err){ console.log("connected? err=", err, "info=", wifi.getIP()); }); wifi.stopAP(); wifi.save();
And i'm connected, but next time i do reset() cycle and i try to write a wifi.getIP() i get this response
>wifi.getIP() Uncaught ReferenceError: "wifi" is not defined at line 1 col 5 wifi.getIP() ^
It looks like the code is not stored into the flash
-
Ok, got it (honestly i haven't realized what the function E.on do, but anyway... at the moment is working).
E.on('init', function(){ var wifi = require("Wifi"); wifi.connect("ssid", {password: "password"}, function(err){if(err)console.log(err); else { console.log("connesso!"); var http = require("http"); http.createServer(function (req, res) { res.writeHead(200); res.end("Hello World"); }).listen(8080);}}); });
And after send the code, do a save(); to store the program from RAM to FLASH.
Thanks to everyone as pointed me to the solution.
Marco -
-
Ok, after a while i successfull built something that seems to work:
function onInit(){ var wifi = require("Wifi"); wifi.connect("ssid", {password: "password"}, function(err){if(err)console.log(err); else { console.log("connesso!"); var http = require("http"); http.createServer(function (req, res) { res.writeHead(200); res.end("Hello World"); }).listen(8080);}}); wifi.save(); } save();
Since @tve pointed me to the good explanation of @allObjects things are slightly more clear.
Thanks everyone! -
@tve thanks, I've tried to do a search before post my question but I haven't found that thread. Maybe I did a wrong search.
@MaBe what I found is that when I do a Wifi setup (from the tve tutorial) and I save it, next time I boot the esp, the settings are not saved and I have to repeat the whole process (I've followed the tutorial step by step). How is that possible?
Thanks guys, I hope one day I can be useful to the community too. -
Hi MaBe
if i write thissave(); var http = require("http"); http.createServer(function (req, res) { res.writeHead(200); res.end("Hello World"); }).listen(8080);
i get this
http://espruino.com 1v84.tve_master_588d193 Copyright 2015 G.Williams WARNING: the esp8266 port is in beta! Flash map 4MB:512/512, manuf 0xe0 chip 0x4016 >echo(0); Erasing Flash..... Writing... Compressed 12276 bytes to 702 CheckUncaught ReferenceError: "s" is not defined at line 1 col 2 s.writeHead(200); ^
And after if i load()
it stays>load() =undefined Loading 702 bytes from flash...
without doing nothing forcing me to switch reboot the esp
-
Hi tve, digging a little bit into the documentation i've found that save() save the code on the flas after (not before) the code i wrote, is it right? Is it bettor to use E.on('init',function()) instead of save?
What i'm expecting is to try to save the code inside the flash so next time the esp boot it will read the code i wrote (i'm a little bit confused about this, because i understand that when the esp boot read immediately the espruino firmware and the javascript interpreter so the code need to be readed after the firmware... sorry if it can be stupid but i'm trying to understand how it works)so now writing save(); before the code i've got this error:
Erasing Flash..... Writing... Compressed 12276 bytes to 703 CheckUncaught SyntaxError: Got '(' expected ID at line 1 col 10 function (req, res) { ^
and to reply to your question, if i type reset()
_____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |_____|___| _|_| |___|_|_|_|___| |_| http://espruino.com 1v84.tve_master_588d193 Copyright 2015 G.Williams WARNING: the esp8266 port is in beta! Flash map 4MB:512/512, manuf 0xe0 chip 0x4016
another strange behave that i found is when the ide send the code to the esp (without trying to save) i receive a warning message that "the module http is not found" but the webserver work.
Many thanks.
Marco -
Hi guys, first of all my apologies if i ask some newbie question but i have this problem and i can't find a solution for that.
I've flashed my esp-12 with the latest firmware (thanks tve) and and if i try to save my code adding save(), the web IDE return erasing flash... writing... compressed byte (numbers) bytes to (numbers) but it hasn't saved nothing, just erased the flash.
I've tried only to send an the http server example:var http = require("http");
http.createServer(function (req, res) {
res.writeHead(200);
res.end("Hello World");
}).listen(8080);and it works but just adding save() at the end of the code, erase the flash but the code don't work.
What i'm doing wrong?
Thanks for your time guys
Marco
@Ollie, also thanks for the tip of gitter. I think here i'm going offtopic