Commencé à bosser sur le plugin NodeMCU pour Atom
This commit is contained in:
19
IDE_remote/SocketIDE/atom_plugin/test1/_secrets_energy.lua_
Normal file
19
IDE_remote/SocketIDE/atom_plugin/test1/_secrets_energy.lua_
Normal file
@@ -0,0 +1,19 @@
|
||||
-- Petit script pour configurer les choses secrètes que l'on n'aimerait
|
||||
-- pas être exportées sur Internet (github)
|
||||
-- donc on ne met PAS des secrets dans le code !
|
||||
-- faut le mettre ailleurs que dans le dépôt !
|
||||
-- il faut le renommer en 'secrets_energy.lua' et sera exécuté
|
||||
-- par 'boot.lua' au moment du boot
|
||||
|
||||
function secrets()
|
||||
print("\n secrets_energy.lua zf190916.1458 \n")
|
||||
|
||||
cli_ssid="xxx"
|
||||
cli_pwd="xxx"
|
||||
|
||||
influxdb_url="http://xxx.yyy.zzz:8086/write?db=xxx&u=admin&p=xxx"
|
||||
print("influxdb_url: "..influxdb_url)
|
||||
|
||||
end
|
||||
secrets()
|
||||
secrets=nil
|
||||
@@ -1,3 +1,7 @@
|
||||
--Script de bootstrap, test au moment du boot qui a été la cause de boot.
|
||||
|
||||
print("\n init.lua zf191021.0914 \n")
|
||||
|
||||
local bootreasons={
|
||||
[0]="power-on",
|
||||
[1]="hardware watchdog reset",
|
||||
@@ -13,6 +17,15 @@ if ip then
|
||||
print("already got:"..ip)
|
||||
else
|
||||
print("Connecting...")
|
||||
-- charge ses propres secrets
|
||||
f= "secrets_energy.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
-- configure le WIFI
|
||||
f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
--[[
|
||||
wifi.setmode(wifi.STATION)
|
||||
ip_cfg={}
|
||||
ip_cfg.ip = "192.168.6.90"
|
||||
@@ -26,11 +39,13 @@ else
|
||||
wifi.sta.config(station_cfg)
|
||||
wifi.sta.connect()
|
||||
wifi.sta.autoconnect(1)
|
||||
]]
|
||||
|
||||
tmr.alarm(0, 1000, 1, function ()
|
||||
plugtimer1=tmr.create()
|
||||
plugtimer1:alarm(1*1000, tmr.ALARM_AUTO, function()
|
||||
local ip = wifi.sta.getip()
|
||||
if ip then
|
||||
tmr.stop(0)
|
||||
plugtimer1:unregister()
|
||||
print(ip)
|
||||
end
|
||||
end)
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
version = "0.6.5 zf191020.1804"
|
||||
version = "0.6.5 zf191020.2041"
|
||||
|
||||
print("luatool.py ver " + version)
|
||||
|
||||
@@ -195,24 +195,24 @@ def decidetransport(cliargs):
|
||||
if __name__ == '__main__':
|
||||
# parse arguments or use defaults
|
||||
parser = argparse.ArgumentParser(description='ESP8266 Lua script uploader.')
|
||||
parser.add_argument('-p', '--port', default='/dev/ttyUSB0', help='Device name, default /dev/ttyUSB0')
|
||||
# parser.add_argument('-b', '--baud', default=9600, help='Baudrate, default 9600')
|
||||
parser.add_argument('-b', '--baud', default=115200, help='Baudrate, default 115200')
|
||||
parser.add_argument('-f', '--src', default='main.lua', help='Source file on computer, default main.lua')
|
||||
parser.add_argument('-t', '--dest', default=None, help='Destination file on MCU, default to source file name')
|
||||
parser.add_argument('-c', '--compile', action='store_true', help='Compile lua to lc after upload')
|
||||
parser.add_argument('-r', '--restart', action='store_true', help='Restart MCU after upload')
|
||||
parser.add_argument('-d', '--dofile', action='store_true', help='Run the Lua script after upload')
|
||||
parser.add_argument('-v', '--verbose', action='store_true', help="Show progress messages.")
|
||||
parser.add_argument('-a', '--append', action='store_true', help='Append source file to destination file.')
|
||||
parser.add_argument('-l', '--list', action='store_true', help='List files on device')
|
||||
parser.add_argument('-w', '--wipe', action='store_true', help='Delete all lua/lc files on device.')
|
||||
parser.add_argument('-i', '--id', action='store_true', help='Query the modules chip id.')
|
||||
parser.add_argument('-e', '--echo', action='store_true', help='Echo output of MCU until script is terminated.')
|
||||
parser.add_argument('--bar', action='store_true', help='Show a progress bar for uploads instead of printing each line')
|
||||
parser.add_argument('--delay', default=0.03, help='Delay in seconds between each write, default 0.03 sec.', type=float)
|
||||
parser.add_argument('--delete', default=None, help='Delete a lua/lc file from device.')
|
||||
parser.add_argument('--ip', default=None, help='Connect to a telnet server on the device (--ip IP[:port])')
|
||||
parser.add_argument('--ip', default=None, help='Connect via telnet server (--ip IP[:port])')
|
||||
parser.add_argument('--zrestart', action='store_true', help='Restart the NodeMCU.')
|
||||
parser.add_argument('-a', '--append', action='store_true', help='Append source file to destination file.')
|
||||
parser.add_argument('-b', '--baud', default=115200, help='Baudrate, default 115200')
|
||||
parser.add_argument('-c', '--compile', action='store_true', help='Compile lua to lc after upload')
|
||||
parser.add_argument('-d', '--dofile', action='store_true', help='Run the Lua script after upload')
|
||||
parser.add_argument('-e', '--echo', action='store_true', help='Echo output of MCU until script is terminated.')
|
||||
parser.add_argument('-f', '--src', default='main.lua', help='Source file on computer, default main.lua')
|
||||
parser.add_argument('-i', '--id', action='store_true', help='Query the modules chip id.')
|
||||
parser.add_argument('-l', '--list', action='store_true', help='List files on device')
|
||||
parser.add_argument('-p', '--port', default='/dev/ttyUSB0', help='Device name, default /dev/ttyUSB0')
|
||||
parser.add_argument('-r', '--restart', action='store_true', help='Restart MCU after upload')
|
||||
parser.add_argument('-t', '--dest', default=None, help='Destination file on MCU, default to source file name')
|
||||
parser.add_argument('-v', '--verbose', action='store_true', help="Show progress messages.")
|
||||
parser.add_argument('-w', '--wipe', action='store_true', help='Delete all lua/lc files on device.')
|
||||
args = parser.parse_args()
|
||||
|
||||
transport = decidetransport(args)
|
||||
@@ -224,7 +224,7 @@ if __name__ == '__main__':
|
||||
|
||||
|
||||
if args.list:
|
||||
#zzz191020 Amélioré la sortie du listing des fichiers
|
||||
# zzz191020 Amélioré la sortie du listing des fichiers
|
||||
transport.writeln("print('\\n-----');local l = file.list();for k,v in pairs(l) do print(k..', size:'..v)end;print('-----\\n')\r", 0)
|
||||
while True:
|
||||
char = transport.read(1)
|
||||
@@ -245,6 +245,11 @@ if __name__ == '__main__':
|
||||
print("\n"+id)
|
||||
sys.exit(0)
|
||||
|
||||
# zzz191020 Ajouté la fonction restart seule
|
||||
if args.zrestart:
|
||||
transport.writeln("node.restart()\r")
|
||||
sys.exit(0)
|
||||
|
||||
if args.wipe:
|
||||
transport.writeln("local l = file.list();for k,v in pairs(l) do print(k)end\r", 0)
|
||||
file_list = []
|
||||
@@ -271,6 +276,8 @@ if __name__ == '__main__':
|
||||
|
||||
if args.dest is None:
|
||||
args.dest = basename(args.src)
|
||||
### zzz191020 Affiche le fichier à envoyer
|
||||
print("File: " + args.src)
|
||||
|
||||
# open source file for reading
|
||||
try:
|
||||
@@ -354,6 +361,7 @@ if __name__ == '__main__':
|
||||
# restart or dofile
|
||||
if args.restart:
|
||||
transport.writeln("node.restart()\r")
|
||||
|
||||
if args.dofile: # never exec if restart=1
|
||||
transport.writeln("dofile(\"" + args.dest + "\")\r", 0)
|
||||
|
||||
|
||||
@@ -1,10 +1,36 @@
|
||||
#!/bin/bash
|
||||
# Petit script pour télécharger facilement tout le binz
|
||||
#zf191020.1745
|
||||
#zf191021.0915
|
||||
|
||||
# S'il y a des erreurs lors d'un téléchargement, il faut simplement augmenter un peu le délai !
|
||||
# Il est préférable de télécharger en premier les *gros* fichiers .lua !
|
||||
|
||||
#ATTENTION: cela efface tout le NodeMCU !
|
||||
|
||||
luatool_tty="/dev/cu.wchusbserial1410"
|
||||
|
||||
read -p "ATTENTION, cela va effacer tout le NodeMCU !"
|
||||
read -p "Etes-vous vraiment certain ?"
|
||||
|
||||
chmod +x luatool.py
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 -l
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 -f websocket.lua
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 -f main.lua
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 -f init.lua
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 -l
|
||||
./luatool.py --port $luatool_tty -w
|
||||
./luatool.py --port $luatool_tty --zrestart
|
||||
sleep 0.5
|
||||
./luatool.py --port $luatool_tty -l
|
||||
read -p "Est-ce bien vide ?"
|
||||
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.04 -f websocket.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f main.lua
|
||||
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 --bar --delay 0.001 --src secrets_energy.lua
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 --bar --delay 0.001 --src wifi_ap_stop.lua
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 --bar --delay 0.001 --src wifi_cli_conf.lua
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 --bar --delay 0.001 --src wifi_cli_start.lua
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 --bar --delay 0.001 --src wifi_info.lua
|
||||
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f initz.lua -t init.lua
|
||||
./luatool.py --port $luatool_tty -l
|
||||
|
||||
read -p "Pas eu d'erreur, on redémarre et part à fond ?"
|
||||
./luatool.py --port $luatool_tty --zrestart
|
||||
echo -e "\nC'est tout bon ;-)"
|
||||
|
||||
10
IDE_remote/SocketIDE/atom_plugin/test1/wifi_ap_stop.lua
Normal file
10
IDE_remote/SocketIDE/atom_plugin/test1/wifi_ap_stop.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
-- Démarre le WIFI en mode AP
|
||||
print("\n wifi_ap_stop.lua zf180824.2000 \n")
|
||||
|
||||
local zmodewifi=wifi.getmode()
|
||||
if zmodewifi == wifi.SOFTAP then
|
||||
wifi.setmode(wifi.NULLMODE)
|
||||
elseif zmodewifi == wifi.STATIONAP then
|
||||
wifi.setmode(wifi.STATION)
|
||||
end
|
||||
print("WIFI AP arrêté")
|
||||
11
IDE_remote/SocketIDE/atom_plugin/test1/wifi_cli_conf.lua
Normal file
11
IDE_remote/SocketIDE/atom_plugin/test1/wifi_cli_conf.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
-- Petit script pour configurer le client WIFI du NodeMCU
|
||||
|
||||
function wifi_cli_conf()
|
||||
print("\n wifi_cli_conf.lua zf190726.1912 \n")
|
||||
|
||||
-- les secrets sont maintenant initialisés par boot.lua !
|
||||
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, save=true}
|
||||
end
|
||||
|
||||
wifi_cli_conf()
|
||||
wifi_cli_conf=nil
|
||||
20
IDE_remote/SocketIDE/atom_plugin/test1/wifi_cli_start.lua
Normal file
20
IDE_remote/SocketIDE/atom_plugin/test1/wifi_cli_start.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
-- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM
|
||||
|
||||
function wifi_cli_start()
|
||||
print("\n wifi_cli_start.lua zf190310.1519 \n")
|
||||
|
||||
local zmodewifi=wifi.getmode()
|
||||
if zmodewifi == wifi.NULLMODE then
|
||||
print("WIFI mode CLI only")
|
||||
wifi.setmode(wifi.STATION)
|
||||
elseif zmodewifi == wifi.SOFTAP then
|
||||
print("WIFI mode AP+CLI")
|
||||
wifi.setmode(wifi.STATIONAP)
|
||||
end
|
||||
wifi.sta.autoconnect(1)
|
||||
wifi.sta.connect()
|
||||
--f= "wifi_get_ip.lua" if file.exists(f) then dofile(f) end
|
||||
end
|
||||
|
||||
wifi_cli_start()
|
||||
wifi_cli_start=nil
|
||||
33
IDE_remote/SocketIDE/atom_plugin/test1/wifi_info.lua
Normal file
33
IDE_remote/SocketIDE/atom_plugin/test1/wifi_info.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
-- Petit script pour afficher les infos actuel du WIFI
|
||||
print("\n wifi_info.lua zf190727.1220 \n")
|
||||
|
||||
local zmodewifi=wifi.getmode()
|
||||
|
||||
--wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP
|
||||
|
||||
if zmodewifi == wifi.NULLMODE then
|
||||
print("WIFI OFF")
|
||||
elseif zmodewifi == wifi.STATION then
|
||||
print("WIFI mode CLI")
|
||||
print("Connected IP:\n",wifi.sta.getip())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
elseif zmodewifi == wifi.SOFTAP then
|
||||
print("WIFI mode AP")
|
||||
print("AP MAC:\n",wifi.ap.getmac())
|
||||
print("AP IP:\n",wifi.ap.getip())
|
||||
print("AP Connect:\n",wifi.ap.getconfig())
|
||||
elseif zmodewifi == wifi.STATIONAP then
|
||||
print("WIFI mode CLI+AP")
|
||||
print("Connected IP:\n",wifi.sta.getip())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
print("AP MAC: ", wifi.ap.getmac())
|
||||
print("AP IP: ", wifi.ap.getip())
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# Petit script pour télécharger facilement tout le binz
|
||||
#zf191020.2053
|
||||
#zf191021.0844
|
||||
|
||||
# S'il y a des erreurs lors d'un téléchargement, il faut simplement augmenter un peu le délai !
|
||||
# Il est préférable de télécharger en premier les *gros* fichiers .lua !
|
||||
@@ -15,6 +15,7 @@ chmod +x luatool.py
|
||||
sleep 0.5
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 -w
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 -l
|
||||
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 --bar --delay 0.06 --src telnet_srv2.lua
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 --bar --delay 0.001 --src boot.lua
|
||||
./luatool.py --port /dev/cu.wchusbserial1410 --bar --delay 0.001 --src boot2.lua
|
||||
|
||||
Reference in New Issue
Block a user