Problem with save() #5252
Replies: 1 comment
-
Posted at 2016-01-10 by tve What do you expect it to do and what are you observing? Posted at 2016-01-10 by MarcoM 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? so now writing save(); before the code i've got this error:
and to reply to your question, if i type reset()
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. Posted at 2016-01-10 by @MaBecker use load(); to get your code back and then use dump(); to display saved code Posted at 2016-01-10 by MarcoM Hi MaBe
i get this
And after if i load()
without doing nothing forcing me to switch reboot the esp Posted at 2016-01-10 by @MaBecker try this
Posted at 2016-01-10 by tve Maybe this thread helps? http://forum.espruino.com/conversations/278526 Posted at 2016-01-10 by @MaBecker what about the wifi setup code ? Posted at 2016-01-10 by tve http://microcosm.app/out/uvYYg Posted at 2016-01-10 by MarcoM @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. Posted at 2016-01-10 by MarcoM Ok, after a while i successfull built something that seems to work:
Since @tve pointed me to the good explanation of @allObjects things are slightly more clear. Posted at 2016-01-10 by MarcoM No.. it works only when i'm connected to the web ide via serial. Posted at 2016-01-10 by MarcoM Ok, got it (honestly i haven't realized what the function E.on do, but anyway... at the moment is working).
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. Posted at 2016-01-10 by tve Please check out this draft tutorial http://microcosm.app/out/uvYYg for setting up your wireless so you can remove the wifi.connect stuff from your code. Then you start you code with the require("http") and http.creaseServer. You don't need to wait for the esp to actually connect to your wifi to start the http server. Posted at 2016-01-10 by MarcoM @tve. I tried to put
And i'm connected, but next time i do reset() cycle and i try to write a wifi.getIP() i get this response
It looks like the code is not stored into the flash Posted at 2016-01-10 by tve The wifi code is not supposed to be stored in the flash. start with reset(), then save() to empty what you have stored. Then ensure you have a wifi connection. Then wifi.save(). Then restart and make sure it comes up again and connects. Then load your code (without wifi commands) and save() it. Posted at 2016-01-11 by MarcoM @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. Posted at 2016-01-12 by tve Upgrading is a good idea :-) Posted at 2016-01-12 by @allObjects @marcom, taking a look at ...explanation what save () does may help you to sort things out. What I did not cover there is what has to be done to make sure that after reset / power cycle 'ALL things are there to resume normal operation'. For my stuff I use sequencer and initializer that makes that happen. Decent SW design tries to separate concerns. Even though all things can abstractly be looked at as resources and treated equally - also sequence / time wise - they are not equal, and on top of it they have (inter)dependencies of existence and sequence / time. As if this is not enough complex yet, asynchronousity is added to the . Promises save you from callback hell, but they are not simple heaven either... ;-) Posted at 2016-01-12 by MarcoM 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). Posted at 2016-01-12 by Ollie @marcom. Can I help you on this? I've covered many of the steps you're talking about, but though I haven't seen those particularly obstacles maybe I can. Also do you know of the Espruino Gitter channel? https://gitter.im/espruino/Espruino Posted at 2016-01-12 by MarcoM @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. Posted at 2016-01-12 by MarcoM @ollie, also thanks for the tip of gitter. I think here i'm going offtopic Posted at 2016-01-12 by Ollie No this is good here, but gitter sometimes faster - that's the only reason I mentioned it. That is a good question. Using http://www.espruino.com/Reference#t_l_Wifi_getStatus I have code to refactor now that the ESP8266 port is really quite polished. The above will be my approach. We need the "station" property and will be looking for "connected" as the value. Posted at 2016-01-13 by @allObjects @marcom, ...regarding sequencer... Think about your electronics: some things you time - delay - with an RC-circuit, and some you setup for trigger on a rising or falling edge. That sums it up quite simply... may be a bit too simply, but it is a good starting point. Post continues in this post as part of the conversation that deals with |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-01-10 by MarcoM
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
Beta Was this translation helpful? Give feedback.
All reactions