-->
Page 1 of 2

smart.js learning pains

PostPosted: Mon Dec 14, 2015 5:12 pm
by BillC
I just started experimenting with smart.js this past weekend and it was a little painful to get started. I had bought a Adafruit Huzzah development board, it comes with the Lua interpreter installed, and I was able to work with it via ESPlorer. All well and good, but I know JavaScript a heck of a lot better than Lua so I wanted to try out smart.js - https://www.cesanta.com/developer/smartjs#_overview.

My first obstacle was getting it to flash onto the Huzzah. The default board firmware appears to be set at 9600 baud, but the Cesanta utility (FlashNChips) wants 115200. I had to dig around and find an esptool binary that would run on my Mac laptop, and then use it to flash the firmware files via the command line at a designated baud rate. Finally succeeded and it boots to the smart.js prompt. I was able to load and run some of the demo scripts that connect to WiFi and webservers, etc. which is encouraging.

Now trying to write some simple scripts of my own I am running into an odd problem, maybe people will have suggestions. One mechanism for this is to write code on your laptop or whatever and save it to a file, then use the 'upload' function of FlashNChips to transmit the code files across the USB/serial cable to the resident filesystem on the ESP8266. Then you can 'eval' them there via a console command in order to run the code or load functions that you can invoke later.

What I'm seeing is that frequently the code file appears to fail to load onto the board cleanly. Looks like the upload utility converts the text file to chunks of UTF8 and then does a series of file writes, one for each chunk. I suspect that the receiving end is getting overrun and the write commands don't complete. It probably can't write out the data to memory as fast as its coming in? If so you would think throttling would be exerted on the data port, but maybe that's not happening properly. Anyone else seeing this? Do I have something put together wrong?

Another option is to use their 'webdav' feature which I haven't been able to try yet. You actually mount the board's filesystem onto your laptop over WiFi and supposedly edit files directly.

Re: smart.js learning pains

PostPosted: Tue Dec 15, 2015 5:41 pm
by BillC
A couple of updates in case anyone is interested.

After further struggles with uploading files I finally reflashed the ESP8266 with the smart.js firmware and mysteriously I was then able to upload files to it successfully again with the console utility. For a while. It appears to eventually reach a state where files can't be written to it or overwritten, and then you have to reflash it. Some kind of intermittent filesystem corruption issue? Flashing takes only a minute or two, inconvenient but not a show stopper. Presumably this will be fixed in subsequent releases.

One impressive feature is that this firmware implements webDAV. After connecting the device to my local WiFi network I was actually able to mount its filesystem onto a Mac laptop over the network and cd to it in a terminal window. And edit and manipulate files directly from there! Pretty impressive for a thing the size of a quarter. Sadly the filesystem eventually becomes scrogged in this mode as well and you must reflash.

I wrote a file with some simple JavaScript utilities in it. After uploading you can; File.eval('myFile.js')

Then any functions you wrote are sitting in memory and can be invoked directly from the command line with something like myFunc(). Or of course in your script you could have invoked your functions directly. In general I think this is pretty cool and I plan to write something that can interact with a web server over the internet.

Re: smart.js learning pains

PostPosted: Sun Dec 20, 2015 10:34 am
by Trickuncle
Still using the nodemcu environment here and programming in Lua but I see file uploads with esplorer fail maybe around 10% of the time. Hasn't made a reflash necessary yet though. I thought about going your route and switching to javascript but have much to learn yet before trying that. For the record, I've never used javascript, HTML, CSS, DOM or any client/server stuff so am learning as I go. I'm also using the Adafruit Huzzah.

One other problem I've found is regarding resetting the module after new code has been sent to it. The esplorer program has a 'reset button' to reset the module and this works - some portion of the time. But sometimes, it only appears to work and the module is left still running the previous copy of your program in ram. This led me to all sorts of imaginary problems that didn't really exist. Finally, I noticed a few times that newly coded features I put in were not working and hit the hardware reset button on the module and this cured the problem.

So, yeah, you are not alone! Would appreciate it if you keep posting about your experiences with javascript. The biggest problem I encounter is that something like 90% of the userbase are using Arduinos and their experience rarely has anything to do with writing and running code directly on the modules. So searching for answers to weird problems often finds no usable results. Nothing wrong with Arduinos but it's a totally different environment compared to Lua/javascript.

Re: smart.js learning pains

PostPosted: Sun Dec 20, 2015 1:18 pm
by BillC
Thanks very much for your comments! I've experimented more with smart.js over the past few days to see what works and doesn't work for me. Unfortunately I don't have good news to report.

Uploading code to it successfully continues to be a serious problem. I have both a Mac and a Windows PC, the symptoms are similar with both. My sense from what I am seeing is that either the filesystem or the write speed of the integrated flash are not able to handle 115200 baud, and that baud rate is the only option. There does not appear to be any reliable speed throttling on the USB-to-serial port and it frequently gets overrun. Sometimes this can be remedied by continuously hitting the return key and then some more bytes get sent until eventually you may see the File.close() command go to the device. If this doesn't happen the filesystem seems to get corrupted and unwriteable, even across device resets, and you have to reflash the whole thing which eventually becomes too tedious to endure.

Also I am seeing peculiar behavior of the JavaScript parser. Code that previously compiled just fine will mysteriously have syntax errors on subsequent uploads. The API documentation is atrocious, mainly just some function signatures and a few skimpy examples. I was able to access a website one time from the device with code that I wrote, but afterwards never could succeed.

I understand that this is early code and problems are to be expected, but the developers (Cesanta, and it may be only one guy) have gone silent. So I am putting this on the shelf for a while and going back to Lua for now. Would love to see it work though.