save() with modules where .connect() initializes device (such as RFID reader MFRC522) #912
Replies: 10 comments
-
Posted at 2015-10-25 by @allObjects A story in three pieces ( Intro, Getting there..., Final ): - Getting there... To ready this code to run on battery, The expected code looks then something like this:
For testing in connected state, upload the code and invoke Because you do not (neccessarily) want to save a running timer... (created by Save reports in the console:
World is still perfectly in order: the code works. It is ready for test as saved code running on battery. Btw - as found out later - you do not need the battery to test, you can just plug-in USB again - just for power - and - as expected on power-on (sinse recent version(s)), Nothing... just nothing. (wiring... all checked again and again... still nothing). So I reworked the code a bit before pulling in the source of the module. In the example coe, I did not like all the stuff in the callback, so I changed. I added
As you see in lines Code works connected well, but still does not work completely after saving and running on battery. The simultaneous flashing of both leds indicate that Now is the time to find out why it is not working... I proide only a symmary about how to do that in this post:
I had not to go that far to see what is really 'broken': having not the No point to hold on to the unminified module code... and back to the way things can be done with the require(... and .connect(.... How to do you split .require() from .connect() to make the require(... happen and provide a handle of the module, and invoke .connect(... within onInit() to make the device initialization happen on re-power-up? - Easy"
With the above setup, not just Espruino's timers (created with setInterval(... is recreated/initialized, but also the device... Comment about what about |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-25 by @allObjects A story in three pieces ( Intro, Getting there..., Finally ) - Finally The final code (TL;DR) looks like this ('Fritzing' attached as pic):
Note 1: Line Note 2: The Attachement: 'Fritizing my way...' (one end of the blue needed a bit 'photoshopping' push for visualization)Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-26 by @gfwilliams Ahh, so you're saying the issue was that the NFC module wasn't initialised with There's already a I've thought about trying to make those modules use |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-26 by @allObjects For educational 'playing' while connected and without saving, things work just fine. For modules that connect to devices with dynamic, volatile configurations, save does - and cannot - save the state of the device, because it lives only inside the device and the device doe not have a save and restore function... and even if they would have, Espruino's save() would have to know about it and also know about how to call the particular device's save... Separating the Espruino related initializations from initializations of the connected devices is the key to the solution. It is obvious that build-time oriented things - 'require' - and runtime oriented things - 'connect' - need to be separated - and can therefore not exist in the same statement. Choosing the approach of crating a module reference and use the module reference later in the code is not a viable approach. Having the code structured with getting the resources first and apply basic (static) initialization and then issue a |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-26 by @allObjects ...just tried to 'save()' a simple ESP8266 example... not working well... will have to dig into the nested require issue... Will raise elaborate on the issues in a separate tread... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-26 by tve Please try to capture the debug output from uart1 (gpio pin 2) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-26 by @allObjects What is GPIO2 providing? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-26 by JumJum @allObjects I have been at the same point some days ago.
In my case Espruino is connected to a local copy of WebIDE and ESP8266 is connected to the original WebIDE. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-31 by Moray I wish I had read these experiments before my own work on moving from console-connected to independent operation! Thank you for writing them up. Because I am going to be controlling power to all connected devices, I assume that all connected devices may have been independently powered down, and so (and because of not liking to be reliant on save timing) I prefer to reconnect devices again via a deviceInit function in onInit which is also called in the start section of the main app.m |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-24 by @allObjects @moray, for your work you may also be interested in these two conversations - a bit a lot delayed - response to your post - but still helpful: simple explanation how to save code that espruino run on start? about things that go on on saving / power cycling, and GPS powered by Espruino pin(s). And if you already plowed through these, just ignore this post. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-25 by @allObjects
A story in three pieces ( Intro, Getting there..., Final ):
- Intro
Working on something with
save()
to run it from battery sent me a bit into the boonies...When you
save()
code, it matters very much when you do it... in other words: it matters in what state the board is (after upload) - what initializations have been made, what code did already complete and what code is still running (timeouts, intervalls,...).For illustration purpose, I use the code example with module MFRC522 NFC/RFID MODULE is discussed (see attached pic and next post). The example code works well when connected to the IDE (out of box on Espruino standard board, and with two changes for for Espruino Pico: 1st) B2 has to be changed to B1 because B2 is LED1 and not on connectors - and even if connected, it messes with the example; 2nd) LED3 has to be removed from the array of leds because it is undefined).
PS: It was difficult to catch the green LED on, even though the white RF ID card was laying under the reader and making it flash twice a second for 100ms. The picture shows Espruino Pico 'extended' to 2x14 = 28 pins. The 0.05" connectors are brought to the 'sides' with lacquered wires (plus GND and 3.3V at the rows ends), leaving a prototyping space of 4x5 = 20 wholes. A similar shim could make this into bottom and top SMT areas for I2C / SPI connected EEPROM / FRAM/MRAM / (Atmel) Crypto / security chips.
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions