-
-
-
Hi Robin π!
It's uploaded from the right-hand side, then uploaded to Flash using the "Send to Espruino" button in the IDE.
I have boiled down the code to this (right-hand side):
// ****************************************Β********************* // *** CONST / VARS // ****************************************Β********************* // Pins const PIN_RESET = D17; const PIN_CS = D4; const PIN_SCK = D5; const PIN_MISO = D19; const PIN_MOSI = D23; let sx; // ****************************************Β********************* // *** MAIN // ****************************************Β********************* /* * Called on boot */ function onInit() { try { SPI1.setup({ sck: PIN_SCK, miso: PIN_MISO, mosi: PIN_MOSI }); sx = require('SX127x').connect({ spi: SPI1, cs: PIN_CS, rst: PIN_RESET }); } catch (e) { console.log('e: ', e); } }
Should this be taken literally as actual error text?
No, the error is always as shown below:
Uncaught Error: Radio not found! at line 1 col 65 ...ow Error("Radio not found!");this.setOpMode(0);this.mask(1,1Β...
Persusing the source will reveal what var objects are created as the module is fetched/parsed. Maybe a conditional test against 'undefined' or what might be expected as those are initialized, and/or throw your own user defined error to catch?
I don't quite understand what you are suggesting π. Which properties could I test against
undefined
? I mean the error is happening inside the Espruino module, and apparently I'm unable to catch it externally. Modules are not my strongest side, but should't I be able to do that?--I mean, why throw an error if you are prevented from handling it π€..Thanks for taking the time to help π!
-
Hi π,
I'm getting this error from time to time when using the "SX127x" module in a couple of projects (custom HW, and ESP32).
Uncaught Error: Radio not found! at line 1 col 65 ...ow Error("Radio not found!");this.setOpMode(0);this.mask(1,1Β...
I'm not so concerned with why it fails right now (probably bad SPI communication), but I'd like to catch it so I can handle it properly.
I've tried the code below, but I still get
Uncatched Error: ...
in the WEB IDE.try { sx = require('SX127x').connect({ spi: SPI1, cs: PIN_CS, rst: PIN_RESET }); } catch (e) { console.log('Error catched: ', e); }
Q: Can anyone advise me on how I can catch this error--or is there a more general way to catch errors that happen internally in the Espruino modules π?
-
I see your point(s) π.
if it's been less than a day or two since the last release
if a broken firmware is left on the website
I completely agree. And the gain-to-hassle ratio should also be reasonable of course.
I might disagee the day Espruino is powering mission critical components on the Orion Spacecraft though π¬.
-
Any reason why the semver specification is not adopted by the project, Gordon π? (I think it's used with the IDE already, right?)
I see some potential frustrations if people think they have a specific FW version, but not the same behavior, as others π¬. Personally, if I already had version 2.07, I would be very unlikely to download it again. Or is this what the cutting edge builds are meant to cover?
-
Are you sure you should have the extra
.4
in there--where did you get the link π?https://www.espruino.com/binaries/espruiΒno_2v07_pico_1r3.bin -
-
Done π.
There was a small difference between the docs and the git-repo. The line
"Note: This is not available in devices with low ... " was missing from git. But I think you'de need to be more experienced with git and how the docs are synchronized with it to understand why, I didn't add the missing line π. -
When you type dump() it dumps the current state of code in RAM (plus the hardware state), then if there's code saved in flash it writes // Code saved with E.setBootCode and dumps that.
That explains it completely, thanks π!
I think what confused me was the two statements in the docs
- "Output current interpreter state in a text form" -- made me think "why would the interpreter keep the same code twice" and made me question what the interpreter even was then.
- "such that it can be copied to a new device" -- made me think "why would one paste a bunch of code with repeated code blocks into a new device"
Nevertheless; case closed, thanks for your help and patience π.
edit: BTW, may I suggest adding the quoted text to the docs (or is it something anyone can do via a PR on github?) π? It's a very clear explanation IMO.
- "Output current interpreter state in a text form" -- made me think "why would the interpreter keep the same code twice" and made me question what the interpreter even was then.
-
Thanks for clarifying that π. Still, do you know whats going on with the code being there twice? I just can't get my head around why the interpreter would hold the original code plus a copy (dump() docs states that the output is the "current state of" the interpreter) π€..
Its like "slightly modified code" +
jshPinDefaultPullup()
+ "original code". -
(**edit: ** oh, I think I misunderstood your last suggestion about setting
b
, never mind π)Sure, I'll try that π.
I've updated the test code to:
let b; function onInit() { setTimeout(() => { b = 1; }, 5000); }
The dump now first produces:
>dump() var b = undefined; function onInit() { setTimeout(() => { b = 1; }, 5000); } setTimeout(function (undefined) {b = 1;}, 1840.55); // 1 pinMode(D0, "input_pullup", true); pinMode(D12, "input_pullup", true); pinMode(D13, "input_pullup", true); pinMode(D14, "input_pullup", true); pinMode(D15, "input_pullup", true); pinMode(D18, "input_pullup", true); pinMode(D19, "input_pullup", true); pinMode(D21, "input_pullup", true); pinMode(D22, "input_pullup", true); pinMode(D25, "input_pullup", true); pinMode(D26, "input_pullup", true); pinMode(D27, "input_pullup", true); pinMode(D34, "input_pullup", true); pinMode(D35, "input_pullup", true); pinMode(D36, "input_pullup", true); pinMode(D37, "input_pullup", true); pinMode(D38, "input_pullup", true); pinMode(D39, "input_pullup", true); // Code saved with E.setBootCode let b; function onInit() { setTimeout(() => { b = 1; }, 5000); }=undefined
And after > 5 s
>dump() var b = 1; function onInit() { setTimeout(() => { b = 1; }, 5000); } pinMode(D0, "input_pullup", true); pinMode(D12, "input_pullup", true); pinMode(D13, "input_pullup", true); pinMode(D14, "input_pullup", true); pinMode(D15, "input_pullup", true); pinMode(D18, "input_pullup", true); pinMode(D19, "input_pullup", true); pinMode(D21, "input_pullup", true); pinMode(D22, "input_pullup", true); pinMode(D25, "input_pullup", true); pinMode(D26, "input_pullup", true); pinMode(D27, "input_pullup", true); pinMode(D34, "input_pullup", true); pinMode(D35, "input_pullup", true); pinMode(D36, "input_pullup", true); pinMode(D37, "input_pullup", true); pinMode(D38, "input_pullup", true); pinMode(D39, "input_pullup", true); // Code saved with E.setBootCode let b; function onInit() { setTimeout(() => { b = 1; }, 5000); }=undefined
I think I'm at a point where I really need to now what
dump()
is supposed to do exactly π€. Because if its description is something like "Will return your code transformed to es2015, your default pin configuration, and a copy of your original code", the output makes sense.
I've read https://www.espruino.com/Reference#l__glΒobal_dump of course, but I don't know what is meant by "current interpreter state", or more specifically what the interpreter is supposed to hold exactly π.I think I need @Gordon, just to see if we're on to something, or if the dump() output is as expected.
-
No problem, I'm interested in figuring out if this is in fact an issue (or if I just don't understand what
dump()
is supposed to do) and getting it solved, as much as anybody π.Although I don't have time to setup and determine if I can duplicate, I now do notice that the
variable is declared with both a 'let' and a 'var'This may indeed be the key. Are you defining this differently, or as I read your proceedure
verbatim, it appears to be duplicated after the edit, that way perhaps?Yes, it seems to be duplicated. I haven't used
var
--thats why I guessed on the first code block (above the "pinMode"s) being a copy of my code after some kind of parsing π.About the original issue: the real issue was me expecting the
wifi
-module to useat
-commands for configuration (like theESP8266WiFi_0v25
module). It was a mental lapse on my part. -
Yes-ish, I uploaded #33, got #34, I only edited out password and SSID. The comments where there in the uploaded code, and in the dump. (edit: if your'e refering to the comment saying "// Code saved with E.setBootCode", I think it's generated--I did'nt put it there or anywhere else π)
I could do it once more without my password in there in the first place, so I don't need to edit at all π. But what do you say we change our base test code from the rather verbose above to what I mentioned in #40? I think I can reproduce exactly the same behavior with:
// ****************************************Β******************** // *** MAIN // ****************************************Β******************** let b; function onInit() { let a = 0; }
(The large comment block is not necessary, but included since it seemed of interest to you in your previous question--and I'm curious about the variables defined outside of onInit, hence the
let b
)To make sure I have the cleanest possible starting point, I followed the steps below:
- Going to "DEVICE STORAGE" (from the menu items in the center toolbar of the IDE) and deleted .bootcde file
- Running
reset(true)
(writing directly in L-hand side)
RAM now contains:
pinMode(D0, "input_pullup", true); pinMode(D12, "input_pullup", true); pinMode(D13, "input_pullup", true); pinMode(D14, "input_pullup", true); pinMode(D15, "input_pullup", true); pinMode(D18, "input_pullup", true); pinMode(D19, "input_pullup", true); pinMode(D21, "input_pullup", true); pinMode(D22, "input_pullup", true); pinMode(D25, "input_pullup", true); pinMode(D26, "input_pullup", true); pinMode(D27, "input_pullup", true); pinMode(D34, "input_pullup", true); pinMode(D35, "input_pullup", true); pinMode(D36, "input_pullup", true); pinMode(D37, "input_pullup", true); pinMode(D38, "input_pullup", true); pinMode(D39, "input_pullup", true);
Dump()'ing (L-hand side) provides:
____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 2v06 (c) 2019 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate > > >dump() pinMode(D0, "input_pullup", true); pinMode(D12, "input_pullup", true); pinMode(D13, "input_pullup", true); pinMode(D14, "input_pullup", true); pinMode(D15, "input_pullup", true); pinMode(D18, "input_pullup", true); pinMode(D19, "input_pullup", true); pinMode(D21, "input_pullup", true); pinMode(D22, "input_pullup", true); pinMode(D25, "input_pullup", true); pinMode(D26, "input_pullup", true); pinMode(D27, "input_pullup", true); pinMode(D34, "input_pullup", true); pinMode(D35, "input_pullup", true); pinMode(D36, "input_pullup", true); pinMode(D37, "input_pullup", true); pinMode(D38, "input_pullup", true); pinMode(D39, "input_pullup", true); =undefined >
Copy / pasted the following into the R-hand side:
// ****************************************Β******************** // *** MAIN // ****************************************Β******************** let b; function onInit() { let a = 0; }
Uploaded code to Flash using the button in the center toolbar. I waited for the upload to finish, and my console now looks like this:
____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 2v06 (c) 2019 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate > WARNING: Scan stop failed WARNING: set rssi scan not implemeted yet Running onInit()...
Dump'ing (from L-hand side):
>dump() var b = undefined; function onInit() {let a = 0;} pinMode(D0, "input_pullup", true); pinMode(D12, "input_pullup", true); pinMode(D13, "input_pullup", true); pinMode(D14, "input_pullup", true); pinMode(D15, "input_pullup", true); pinMode(D18, "input_pullup", true); pinMode(D19, "input_pullup", true); pinMode(D21, "input_pullup", true); pinMode(D22, "input_pullup", true); pinMode(D25, "input_pullup", true); pinMode(D26, "input_pullup", true); pinMode(D27, "input_pullup", true); pinMode(D34, "input_pullup", true); pinMode(D35, "input_pullup", true); pinMode(D36, "input_pullup", true); pinMode(D37, "input_pullup", true); pinMode(D38, "input_pullup", true); pinMode(D39, "input_pullup", true); // Code saved with E.setBootCode // ****************************************Β******************** // *** MAIN // ****************************************Β******************** let b; function onInit() { let a = 0; }=undefined >
RAM:
var b = undefined; function onInit() {let a = 0;} pinMode(D0, "input_pullup", true); pinMode(D12, "input_pullup", true); pinMode(D13, "input_pullup", true); pinMode(D14, "input_pullup", true); pinMode(D15, "input_pullup", true); pinMode(D18, "input_pullup", true); pinMode(D19, "input_pullup", true); pinMode(D21, "input_pullup", true); pinMode(D22, "input_pullup", true); pinMode(D25, "input_pullup", true); pinMode(D26, "input_pullup", true); pinMode(D27, "input_pullup", true); pinMode(D34, "input_pullup", true); pinMode(D35, "input_pullup", true); pinMode(D36, "input_pullup", true); pinMode(D37, "input_pullup", true); pinMode(D38, "input_pullup", true); pinMode(D39, "input_pullup", true); // Code saved with E.setBootCode // ****************************************Β******************** // *** MAIN // ****************************************Β******************** let b; function onInit() { let a = 0; }
.bootcde-file (accessed from the center toolbar under "DEVICE STORAGE"):
// ****************************************Β******************** // *** MAIN // ****************************************Β******************** let b; function onInit() { let a = 0; }
And I agree, this discussion is probably becoming better suited for somewhere else π.
- Going to "DEVICE STORAGE" (from the menu items in the center toolbar of the IDE) and deleted .bootcde file
-
-
Thanks for chiming in π. This all started with me playing around with
setHostname
but didn't get the results I was hoping for.On http://www.espruino.com/ESP32, theres a note saying "Not currently implemented.", but on https://www.espruino.com/Reference#t_l_WΒifi_setHostname it says "Note: This is only available in ESP8266 boards running Espruino and Espruino WiFi boards and ESP32 boards". Do you know which one is correct? It would explaing some of my earlier issues if it was not supported π.
-
Interesting!
Yes, what I posted was all the output after the "dump()" command was executed π. Right-hand editor only (except from when using dump()/reset()/trace()). The output of trace does not make sense to me π.
Me:
Windows 10 desktop
Espruino IDE 0.73.7
Upload destination: Flash
Hardware: Ai-Thinker ESP32-S
process.env: {
VERSION: "2v06",
GIT_COMMIT: "21168a2b",
BOARD: "ESP32",
FLASH: 0, STORAGE: 262144, RAM: 524288,
SERIAL: "8caab5a2-89e8",
CONSOLE: "Serial1",
MODULES: "Flash,Storage,hea" ... "r,crypto,neopixel",
EXPTR: 1073484860 }Did you post about the issue back then? Maybe we can continue there then.
I tried some simpler code (
function onInit() { let a = 0; }
), but I'm not sure how dump is supposed to work, but if I go to "Device Storage" and inspect the content of "RAM" it seems to hold exactly the same content as dump() outputs (dual onInit() function + pinMode's). If I inspect the .bootcde-file, I see the actual code that I uploaded (single function only, and no pinMode's).Just to expand on what I said by RAM before; if I click
flash
witha = 0
, and inspect the RAM, I see two onInit functions there witha = 0
. If I seta = 1
and inspect the RAM, I then see two functions witha = 1
(this proving that the data is updated--I temporarily had the idea that the first onInit held some data from an old upload).Something else, which might be interesting. If I have
let b;
outside of a function, the first occurence becomesvar b = undefined;
(the next still being let b;), but anything inside functions does not seem to be touched. So I guess the first "copy" (before all the pinMode's) is pre-parsed code, but I wonder why the original is still present though. -
-
Oof, I've been blindly trying out code snippets and fixating on this being a variable scoping-issue, without thinking π€¦βοΈ.
I'm using an Ai-Thinker ESP32-S board, and without knowing the inner workings it makes perfect sense that the internal setup would not be done using AT-commands--as opposed to how a WiFi-board + ΞΌC setup would have to.
Thanks for helping out this far π!
-
Oh, that makes perfect sense, thanks π! Unfortunately it means that I can't easily take the wifi-module source code and add the extra functionaly in there directly--so I have to stick with the current approach.
Great suggestion with using dump π. It does seem a little strange. It's as if some stuff (eg. the onInit) is defined twice. I guess the pinMode is stuff generated by default. This is what I get:
var ssid = "EDITED OUT"; var password = "EDITED OUT"; var Wifi = undefined; function onInit() { const w = wifi.connect(ssid, { password: password }, () => { console.log("Connected"); Wifi = w; wifi.enableMDNS("abcd", "iot", 80, function (result) { console.log("enableMDNS result: " + result); }); }); } pinMode(D0, "input_pullup", true); pinMode(D12, "input_pullup", true); pinMode(D13, "input_pullup", true); pinMode(D14, "input_pullup", true); pinMode(D15, "input_pullup", true); pinMode(D18, "input_pullup", true); pinMode(D19, "input_pullup", true); pinMode(D21, "input_pullup", true); pinMode(D22, "input_pullup", true); pinMode(D25, "input_pullup", true); pinMode(D26, "input_pullup", true); pinMode(D27, "input_pullup", true); pinMode(D34, "input_pullup", true); pinMode(D35, "input_pullup", true); pinMode(D36, "input_pullup", true); pinMode(D37, "input_pullup", true); pinMode(D38, "input_pullup", true); pinMode(D39, "input_pullup", true); // Code saved with E.setBootCode // ****************************************Β******************** // *** IMPORTS // ****************************************Β******************** const ssid = "EDITED OUT"; const password = "EDITED OUT"; // ****************************************Β******************** // *** IMPORTS / CONSTANTS // ****************************************Β******************** //const ssid = "<ACCESS_POINT_SSID>"; // const password = "<PASSWORD>"; const wifi = require("Wifi"); let Wifi = null; wifi.enableMDNS = (hostname, serviceType, port, callback) => { let mdns = "AT+MDNS=1," + JSON.stringify(hostname) + "," + JSON.stringify(serviceType) + "," + JSON.stringify(port) + "\r\n"; Wifi.at.cmd(mdns, 500, function (d) { callback(d); }); }; // ****************************************Β******************** // *** MAIN // ****************************************Β******************** /* * Called on boot */ function onInit() { const w = wifi.connect(ssid, { password: password }, () => { console.log("Connected"); Wifi = w; wifi.enableMDNS("abcd", "iot", 80, function (result) { console.log("enableMDNS result: " + result); }); }); }
-
Ah, I see π. I used the access point feature only, so never really had to call
connect
, I updated the example, still getting the same error I'm afraid π€.// ****************************************Β******************** // *** IMPORTS / CONSTANTS // ****************************************Β******************** const ssid = "<ACCESS_POINT_SSID>"; const password = "<PASSWORD>"; const wifi = require("Wifi"); let Wifi; wifi.enableMDNS = function (hostname, serviceType, port, callback) { // <-- Also tried fat-arrow syntax let mdns = "AT+MDNS=1," + JSON.stringify(hostname) + "," + JSON.stringify(serviceType) + "," + JSON.stringify(port) + "\r\n"; Wifi.at.cmd(mdns, 500, function (d) { callback(d); }); }; // ****************************************Β******************** // *** MAIN // ****************************************Β******************** /* * Called on boot */ function onInit() { const w = wifi.connect(ssid, { password: password }, function () { console.log("Connected"); Wifi = w; wifi.enableMDNS("abcd", "iot", 80, function (result) { console.log("enableMDNS result: " + result); }); }); }
-
Sure, here it is π:
// ****************************************Β******************** // *** IMPORTS // ****************************************Β******************** const wifi = require("Wifi"); wifi.enableMDNS = function (hostname, serviceType, port, callback) { let mdns = "AT+MDNS=1," + JSON.stringify(hostname) + "," + JSON.stringify(serviceType) + "," + JSON.stringify(port) + "\r\n"; this.at.cmd(mdns, 500, function (d) { callback(d); }); }; // ****************************************Β******************** // *** MAIN // ****************************************Β******************** /* * Called on boot */ function onInit() { wifi.startAP("EspruinoAP", { password: "0123456789", authMode: "wpa2" }, function (err) { if (err) throw err; console.log("AP created!"); wifi.enableMDNS("abcd", "iot", 80, function (result) { console.log("enableMDNS result: " + result); }); }); }
That was my guess as well, but replacing
this
withwifi
gives me exactly the same error π€.```
2v06 (c) 2019 G.Williams
Espruino is Open Source. Our work is supported
only by sales of official boards and donations:
http://espruino.com/DonateWARNING: Scan stop failed
WARNING: set rssi scan not implemeted yet
Running onInit()...
AP created!
Uncaught Error: Cannot read property 'cmd' of undefined
at line 2 col 12wifi.at.cmd(mdns, 500, function (d) { ^
in function "enableMDNS" called from line 6 col 10
}); ^
in function called from system```
-
Hi Robin π.
Thanks for your suggestion! Sorry, I don't see what information I'm supposed to be getting from https://github.com/espruino/Espruino/bloΒb/master/libs/network/jswrap_wifi.c#L207Β π₯. How does this provide me with the source code of the wifi-module π?
About post #19: yes, indianaJones ends up suggesting some code based on #19, in post #23, and this is the code I'm trying to use.
http://forum.espruino.com/comments/14957Β853/ -
Hey π!
I'm trying to "patch" the wifi-module with indianajones's example in my root file after importing the wifi-module, but I'm getting this error:
Uncaught Error: Cannot read property 'cmd' of undefined. I understand the problem with thethis
reference and it makes perfect sense, but can someone give me a pointer on how to fix it?As I understand it, I can't get my hands on the module source code because it's a "built-in" module (?), thats why I'm trying to extend it externally.
Hey Robin,
Thanks for taking the time to write such a detailed answer π!
I still havn't learnt how the output from
dump()
can help me out--I'm still just a novice in all this Espruino business π. I'll have to read up on that sometime.Yes, I got the same result regarding the source of the error.
As AkosLukacs suggests, the reason seems to be that it's eventually thrown inside a setTimeout ?
Sure, I'm not blaming anyone for making code for free, and I'm extremely satisfied with the library--I was just explaining that my assertion on JavaScript is that errors should be catchable, but apparently in some cases are not π.
So I guess the case is closed--I'll never be able to catch it π€. Catching the error was my only concern of this thread, fixing the communication is not going to be a problem.
Thank you so much for helping out again, you are always very thorough π!