-
• #2
Found the problem.
var creds = require("credsXYZ.js");
should be
var creds = require("credsXYZ"); -
• #3
Thanks for updating it with the answer - any idea why it worked on the 2nd or 3rd send?
-
• #4
This example always fails with "module.js".
Other code that use just the module name produce the intermittent load problem, that resolves after several attempts. Perhaps one day I will stumble on a simple example that can be used to resolve the issue. -
• #5
Tried in console the following... according to Modules reference:
>reset() =undefined _____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |_____|___| _|_| |___|_|_|_|___| |_| http://espruino.com 1v92 Copyright 2016 G.Williams >Modules.removeAllCached(); =undefined >Modules.getCached() =[ ] >Modules.addCached("credsTest",'{ssid: "ssidVal"}'); =undefined Uncaught SyntaxError: Got ':' expected EOF at line 1 col 8 {ssid: "ssidVal"} ^ >Modules.addCached("credsTest",'{"ssid": "ssidVal"}'); =undefined Uncaught SyntaxError: Got ':' expected EOF at line 1 col 8 {"ssid": "ssidVal"} ^ >
Both - non-JSON and JSON - ways fail... I suspect that the new feature to load modules as a function meddles with the previous workings... may be the issue is with both, upload AND pull (
require("...");
)...@Gordon, could it be that the feature of saving modules as functions is doing things differently?
*** BUT*** *** BUT*** *** BUT*** *** BUT*** *** BUT***
Doing it in a module:
// credsTest.js exports = { ssid: "ssidVal", pw: "pwValue" };
...and in the code as follows:
// credsObjTest.js var creds = require("credsTest"); function onInit() { console.log("creds object:"); console.log(creds); console.log("Modules as loaded:"); console.log(Modules.getCached()); } // for the laxy developer at development time: setTimeout(onInit,1000);
...I get this output on upload:
> _____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |_____|___| _|_| |___|_|_|_|___| |_| http://espruino.com 1v92 Copyright 2016 G.Williams > =undefined creds object: { "ssid": "ssidVal", "pw": "pwValue" } Modules as loaded: [ "credsTest" ] >
The last line is only that I do not have to enter
onInit()
in the console. Saving the code without the last line on my PICO I get following output (...becausesave()
invokesonInit()
and I'm still connected):>save() =undefined Erasing Flash..... Writing..... Compressed 81600 bytes to 3066 Checking... Done! Running onInit()... creds object: { "ssid": "ssidVal", "pw": "pwValue" } Modules as loaded: [ "credsTest" ] >
@ClearMemory041063, I do not know what it fighting you...
@Gordon, made another try in the console with (modules source code and not just source code):
>reset() =undefined _____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |_____|___| _|_| |___|_|_|_|___| |_| http://espruino.com 1v92 Copyright 2016 G.Williams >Modules.removeAllCached(); =undefined >Modules.getCached(); =[ ] >Modules.addCached("credsTest",'exports = {ssid: "ssidVal"};'); =undefined >Modules.getCached(); =[ "credsTest" ] >require("credsTest"); ={ "ssid": "ssidVal" } >
And it works, works, works,... nothing is broken... (so: @Gordon, never mind my comments from before...)
-
• #6
Yes, the issue is that
Modules.addCached
is expecting a statement, but you were giving it an expression.If you typed
{ssid: "ssidVal"}
at the console it'd fail too, because when it sees{
it's expecting a block of code and not JSON.To work around it, you can surround the JSON in brackets:
({ssid: "ssidVal"})
- but in this case it's not actually going to have the effect you want.
The error that shows up on occasion in other projects but here it's persistant
ERROR: SD card must be setup with E.connectSDCard first
The error occasionally occurs when other modules are required, but usually clears on a 2nd or third send to Espruino.
The code is an example from @allObjects
The credsXYZ.js module in the sandbox
The output