WARNING: Module "DHT22" not found #6472
Replies: 1 comment
-
Posted at 2017-09-07 by @gfwilliams Might you have had a dodgy (or broken) internet connection when you tried the upload? Posted at 2017-09-07 by Alexander Can be. It is possible to move the modules to the computer? Posted at 2017-09-07 by @MaBecker Yes - copy them into modules folder in your project folder Posted at 2017-09-07 by Alexander Can be more of where and what to lay down I downloaded the files from http://www.espruino.com/modules/ .If you just put the files in the project folder it does not work. EspruinoWiFi.min What are you doing wrong? Posted at 2017-09-07 by @MaBecker Working with ESPRUINO WEB IDE will setup a folder structure On ESP8266 boards ESP8266 an Wifi is build in, so just download DHT22 Posted at 2017-09-07 by @gfwilliams Or you can turn on 'offline mode' in the Web IDE's settings - which might be easier :) Posted at 2017-09-07 by @allObjects Modules on local are - have to be - in the modules folder, a peer folder of projects folder. Posted at 2017-09-23 by PeterS Did you get it to work, I tried all options above, also included path like require("http://www.espruino.com/modules/DHT22.js");
Posted at 2017-09-23 by @allObjects ...yep, np what so ever. Monitored temperature in my upstairs office - more like a sauna - over the CA heat wave recent weeks... ...and I did not need to store the module local. @alexander's struggle got me going and made my get a sensor and run the examples, even added a display and a Web server connecting to my home wireless so I had access to the sensor information from anywhere in the house with my phone over Wifi. Posted at 2017-09-23 by PeterS @allObjects thanks. nice project! Got it working, beginners error :-) I usually type pieces of code in the left side of WEB IDE for syntax errors, only this does not work for require() and external modules. Once I put it on the right side and uploaded it, it worked, not so hot here 22C (Netherlands). Now adding a PIR and LDR and MOSFET, to make it a smart sensor and dim my LED lights. Posted at 2017-09-24 by @allObjects @peters, you get the syntax error info also on the right hand side - in the editor pane. I guess you noticed that by now. Sorry that we did not think of the issue entering the example in the console (right hand side). What you also may have found out is that you can enter everything on the left side, it is just not as convenient. For given DHTH22 sensor example, you would have to enter on the left side following code before you enter the example code (with lines 3..40 being the non-minified, source code of the DHTD22 module from www.espruino.com/modules/DHT22.js) :
...because something like this happens when you upload your code on the right hand side with the Upload to Board button: The upload looks FIRST through your code (with regular expression) to find all require.("...") patterns. For each "...." module reference, the code is pulling from internet or local modules folder and 'shoved the down the throat' of Espruino over the same channel as when you enter stuff on the left side. As SECOND AND LAST, the actual application code is uploaded - again - over the same channel. You just cannot obviously see that because before sending any code, the uploader turns echo in console of and turns it on again after completion of upload. But when you use the Up Arrow key in the console (left hand side) after an upload just happened, you see the last complete JavaScript expression/line that was uploaded... which proves, that the uploader just did what I described above. (You may have read post #8 and post #18 of the conversation about simple explanation how to save code that espruino run on start? which explains these things in more detail. - Luckily, the complexity of sequencing of nonblocking/asynchronous thins or callback-hell where Espruino moves on in the code before things are done is made easy: Promises is available on Espruino and makes writing event driven applications with Espruino even more a breeze.) To complete the exercise of this post - proof that we can enter all in the left side and succeed - we paste now the example in the left hand side (for convenience the example code is repeated here):
There is no real mystery, just pur(e)3.co.uk smartness... 'pure smartness' - I just made that up. No clue where pur in http://pur3.co.uk stands for... may be IT IS pure - with the E facing backwards as some do when obfuscating their password or user id... Cats puRR, may be in 3(D)...)... only @gfwilliams may shed some light on pur3... if he thinks we can handle it... sorry: ...if I can handle it... ;-) Posted at 2024-04-03 by Jurand You can embed the module in your code like this (and there is no need for require anymore): function DHT22(pin) {
this.pin = pin;
}
DHT22.prototype.read = function (cb, n) {
if (!n) n = 10;
var d = '';
var ht = this;
digitalWrite(ht.pin, 0);
pinMode(ht.pin, 'output');
this.watch = setWatch(
function (t) {
d += 0 | (t.time - t.lastTime > 0.00005);
},
ht.pin,
{ edge: 'falling', repeat: true }
);
setTimeout(function () {
pinMode(ht.pin, 'input_pullup');
pinMode(ht.pin);
}, 1);
setTimeout(function () {
if (ht.watch) {
ht.watch = clearWatch(ht.watch);
}
var cks =
parseInt(d.substr(2, 8), 2) +
parseInt(d.substr(10, 8), 2) +
parseInt(d.substr(18, 8), 2) +
parseInt(d.substr(26, 8), 2);
if (cks && (cks & 0xff) == parseInt(d.substr(34, 8), 2)) {
cb({
raw: d,
rh: parseInt(d.substr(2, 16), 2) * 0.1,
temp: parseInt(d.substr(19, 15), 2) * 0.2 * (0.5 - d[18]),
});
} else {
if (n > 1)
setTimeout(function () {
ht.read(cb, --n);
}, 500);
else cb({ err: true, checksumError: cks > 0, raw: d, temp: -1, rh: -1 });
}
}, 50);
};
const dht22 = new DHT22(NodeMCU.D5);
const readDHT22Sensor = () => {
digitalWrite(D2, false);
dht22.read(e => {
console.log(
'[DHT22 sensor] ' +
new Date().toString() +
' temperature: ' +
e.temp.toString() +
'°C, humidity: ' +
e.rh.toString() +
'%'
);
digitalWrite(D2, true);
});
};
readDHT22Sensor();
setInterval(() => readDHT22Sensor(), 1000); Posted at 2024-04-17 by @allObjects sure... but the intention w/ modules in the end is to have them accessed and used like modules. For development it is nice to have them inline. Putting the 'module-frame' around keeps the code as close as possible to the module require() and use pattern. Posted at 2024-07-10 by Jurand I found out, that it works for me only when I use WebIDE: https://www.espruino.com/ide/ |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-09-07 by Alexander
Today has stopped working DHT22 module. What could be the problem? Yesterday everything worked.
1v93 Copyright 2016 G.Williams
Espruino is Open Source. Our work is supported
only by sales of official boards and donations:
http://espruino.com/Donate
Flash map 4MB:512/512, manuf 0xe0 chip 0x4016
Found the problem:
If you are using the Web IDE as is, the modules will be loaded from http://www.espruino.com/modules/. This URL can be changed in Web IDE settings and There is no problem.
The url was https://.
Beta Was this translation helpful? Give feedback.
All reactions