Enfin terminé mon projet de mesure de température à la maison. Cela fonctionne bien maintenant :-)

This commit is contained in:
Christian Zufferey
2019-07-28 12:35:52 +02:00
parent 09c6db84b9
commit 245cd6b45e
16 changed files with 79 additions and 21 deletions

View File

@@ -1,9 +1,19 @@
-- Petit script pour faire office de crontab pour les mesures de température
print("\n 0_cron_temp.lua zf190727.1336 \n")
print("\n 0_cron_temp.lua zf190728.1054 \n")
cron1=tmr.create()
cron1:alarm(10*1000, tmr.ALARM_AUTO, function()
get_temp()
end)
if zfield == 2 then
cron2=tmr.create()
cron2:alarm(20*1000, tmr.ALARM_AUTO, function()
print("cron2........................")
zurl=thingspeak_url.."field1="..tostring(ztemp1).."&field2="..tostring(ztemp2).."&field3="..tostring(ztemp3)
send_temp()
end)
end

View File

@@ -1,5 +1,5 @@
-- Lit le capteur de température solaire en fonction de son field qui se trouve dans les secrets !
print("\n 0_get_temp.lua zf190617.1252 \n")
print("\n 0_get_temp.lua zf190728.1014 \n")
-- lecture: https://thingspeak.com/channels/802784/private_show
-- source: https://nodemcu.readthedocs.io/en/master/modules/ds18b20/
@@ -13,6 +13,8 @@ function get_temp()
print(ind, temp, zfield)
if zfield == 1 then
ztemp1 = temp
zurl=hub_url.."field1="..tostring(ztemp1)
send_temp()
elseif zfield == 2 then
ztemp2 = temp
elseif zfield == 3 then

View File

@@ -5,11 +5,12 @@ Petit projet pour mesurer la température intérieure et extérieure chez moi, a
On peut voir, avec ce projet assez complet, toutes les possibilités offertes de la programmation des NodeMCU en LUA, en mode événementiel. <br>
Choses qui ne seraient pas possible si on l'avait fait en C++ (mode Arduino), comme par exemple:
* serveur WEB service pour le HUB (API)
* serveur WEB pour l'affichage des températures (Active Server Pages ZYX)
* serveur WEB Active Server Pages ZYX, permet de faire des pages HTML avec du code LUA in line
* serveur WEB service pour le HUB (API GET)
* serveur WEB pour l'affichage des températures
* serveur WEB pour l'IDE, modification du code source en remote directement depuis une page WEB, pas besoin d'IDE
* crontab pour les mesures de température
* serveur WEB pour l'IDE, modification du code source en remote
* serveur TELNET, utilisation de la console en remote
* serveur TELNET, utilisation de la console en remote pour le debug
Toutes les fonctions sont bien séparées dans des scripts, ce qui facilite la portabilité entre les projets mais aussi sa mise au point.
@@ -48,9 +49,9 @@ node ow pcm rtctime sntp spi tmr uart wifi ws2812
Comme les mesures de températures sont faites avec 3x NodeMCU différents, il y a donc 3x fichiers de *secrets*. C'est dans ces fichiers de *secrets* qu'il y a l'information de l'adresse IP du NodeMCU qui fait office de *hub* !<br>
```
secrets_temp_zf_int.lua
secrets_temp_zf_out_sud.lua
secrets_temp_zf_out_nord.lua
secrets_temp_int_1er.lua
secrets_temp_out_sud.lua
secrets_temp_out_nord.lua
```
C'est aussi là qu'il y a le *numéro du field* (zfield), c'est à dire le rôle joué par le NodeMCU_Lua:
@@ -66,7 +67,7 @@ Et c'est le **2** qui fait office de *hub*, qui concentre les mesures de tempér
On peut lire la température directement sur le NodeMCU au moyen de cet url (il faut modifier l'adresse IP du NodeMCU en question):
nodemcu xx int, http://192.168.0.171/disp_temp.html
nodemcu 28 int, http://192.168.0.171/disp_temp.html
nodemcu 29 sud, http://192.168.0.180/disp_temp.html
@@ -77,7 +78,7 @@ nodemcu 30 nord, http://192.168.0.105/disp_temp.html
Chaque NodeMCU a son propre serveur WEB, on peut l'accéder simplement depuis son adresse IP:
nodemcu xx int, http://192.168.0.171
nodemcu 28 int, http://192.168.0.171
nodemcu 29 sud, http://192.168.0.180
@@ -88,7 +89,7 @@ nodemcu 30 nord, http://192.168.0.105
Très pratique pour le debug, on peut directement modifier le code source Lua du NodeMCU en remote avec cet url:
nodemcu xx int, http://192.168.0.171:88
nodemcu 28 int, http://192.168.0.171:88
nodemcu 29 sud, http://192.168.0.180:88
@@ -99,7 +100,7 @@ nodemcu 30 sord, http://192.168.0.105:88
Très pratique pour le debug, on peut accéder à la console du NodeMCU en remote avec telnet:
nodemcu xx int, **telnet -rN 192.168.0.171**
nodemcu 28 int, **telnet -rN 192.168.0.171**
nodemcu 29 sud, **telnet -rN 192.168.0.180**
@@ -107,8 +108,11 @@ nodemcu 30 nord, **telnet -rN 192.168.0.105**
## Visualisation sur ThingSpeak
La totale en détail
https://thingspeak.com/channels/817940
Seulement la corrélation entre les trois température
https://thingspeak.com/apps/plugins/300559
zf190727.1447
zf190728.1219

View File

@@ -0,0 +1 @@
-- programme pour faire un test depuis de le webide

View File

@@ -1,6 +1,6 @@
-- Scripts à charger après le boot pour démarrer son appli
print("\n boot.lua zf190727.1341 \n")
print("\n boot.lua zf190728.1009 \n")
function heartbeat()
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
@@ -13,9 +13,9 @@ function heartbeat()
end
-- charge ses propres secrets
f= "secrets_temp_zf_int_1er.lua" if file.exists(f) then dofile(f) end
f= "secrets_temp_zf_out_nord.lua" if file.exists(f) then dofile(f) end
f= "secrets_temp_zf_out_sud.lua" if file.exists(f) then dofile(f) end
f= "secrets_temp_int_1er.lua" if file.exists(f) then dofile(f) end
f= "secrets_temp_out_nord.lua" if file.exists(f) then dofile(f) end
f= "secrets_temp_out_sud.lua" if file.exists(f) then dofile(f) end
--f= "led_rgb.lua" if file.exists(f) then dofile(f) end
--f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 439 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 681 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 655 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 670 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 KiB

View File

@@ -0,0 +1,40 @@
% Template MATLAB code for visualizing correlated data using the
% SCATTER function.
% zf190728.1213
% Prior to running this MATLAB code template, assign the channel variables.
% Set 'readChannelID' to the channel ID of the channel to read from.
% Also, assign the read field IDs to the variables 'fieldID1', and 'fieldID2'.
% Replace the [] with channel ID to read data from:
readChannelID = []];
fieldID1 = 1;
fieldID2 = 2;
fieldID3 = 3;
% Channel Read API Key
% If your channel is private, then enter the read API
% Key between the '' below:
readAPIKey = '';
%% Read Data %%
nbMesures = 200
% Read 1 data variable
[data1, time1] = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumPoints', nbMesures, 'ReadKey', readAPIKey);
% Read 2 data variable
[data2, time2] = thingSpeakRead(readChannelID, 'Field', fieldID2, 'NumPoints', nbMesures, 'ReadKey', readAPIKey);
% Read 3 data variable
[data3, time3] = thingSpeakRead(readChannelID, 'Field', fieldID3, 'NumPoints', nbMesures, 'ReadKey', readAPIKey);
%% Visualize Data %%
plot(time1,data1, time2,data2, time3,data3);
legend({'Tint 1er','Text sud','Text nord'});
xlabel('Time (GMT ! )');
ylabel('Temperature °C');
title('Mesures température 1023 Crissier');

View File

@@ -1,6 +1,6 @@
-- petit script de serveur WEB avec Active Server Page ZYX
print("\n web_srv2.lua zf190709.2209 \n")
print("\n web_srv2.lua zf190728.1021 \n")
ztemp=12
@@ -50,7 +50,8 @@ srv:listen(80, function(conn)
conn:on("receive", function(client, request)
_, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
print("request: \n---\n"..request.."---")
print("zrequest: \n---\n"..request.."---")
-- print("method: ", method) print("path: ", path) print("vars: ", vars)
if not string.find(request, "/favicon.ico") then