Lua скрипты и модули

Alanen

New member
Я вот искал как отправлять почту - чисто структуру заголовка. Нашол такой пример на www.esp8266.com

Код:
function gmail(subject,body)
   us
Немного поправил ваш код:

1)
Если прошивка скомпилирована с cripto то можно сделать так (на время тестирования)
Код:
username = crypto.toBase64("mail plain text")
password = crypto.toBase64("pass plain text")
После
Код:
conn:connect(465,"64.233.164.108") 
   end)
- лишний (строка 30 )

Функция
Код:
net.createConnection(net.TCP, 1)
Warning, deprecated API! net.createConnection with secure flag.
вместо неё надо писать
Код:
 conn=tls.createConnection()
А это вот отсыльщик который мне удалось найти на просторах, немного поправил его, но что-то с логином еще надо пошаманить (никак руки не дойдут) может кто-то все-же заставит его работать.

gamiltest.lua :

Код:
 -- Modifications for GMAIL by Andreas "Andy" Reischle: www.AReResearch.net 
 -- http://www.areresearch.net/2016/04/how-to-send-emails-via-gmail-from.html

-- configure ESP as a station 
local SSID = "AP name" 
local SSID_PASSWORD = "AP pass" 


wifi.setmode(wifi.STATION) 
wifi.sta.config{ssid=SSID, pwd=SSID_PASSWORD}
wifi.sta.autoconnect(1) 


-- The email and password from the account you want to send emails from
--If you have Firmware with crypto module 
local MY_EMAIL = crypto.toBase64("mailfrom@gmail.com")
local EMAIL_PASSWORD = crypto.toBase64("mailpass")
--or wo cripto , must be ecoded to base 64 somewere else
--local MY_EMAIL = "base64login"
--local EMAIL_PASSWORD = "base64password"

-- The SMTP server and port of your email provider.
-- If you don't know it google [my email provider] SMTP settings
local SMTP_SERVER = "smtp.gmail.com"
local SMTP_PORT = "465" --local SMTP_PORT = "993" --local SMTP_PORT = "587"

-- The account you want to send email to
local mail_to = "mailfrom@blabla.com"

 -- These are global variables. Don't change their values 
 -- they will be changed in the functions below 
 local email_subject = "" 
 local email_body = "" 
 local count = 0 
 local conn = nil -- will be used as socket to email server 
 -- The display() function will be used to print the SMTP server's response 
 function display(conn,response) 
    print("Got a response: ") 
    print(response) 
 end 
 -- The do_next() function is used to send the SMTP commands to the SMTP server in the required sequence. 
 -- I was going to use socket callbacks but the code would not run callbacks after the first 3. 
 function do_next() 
       if(count == 0)then 
         count = count+1 
         local IP_ADDRESS = wifi.sta.getip() 
         print ("Send my IP: " .. IP_ADDRESS) 
         --conn:send("EHLO\r\n"); 
         conn:send("HELO "..IP_ADDRESS.."\r\n") 
       elseif(count==1) then 
         count = count+1 
         conn:send("AUTH LOGIN\r\n") 
       elseif(count == 2) then 
         count = count + 1 
         conn:send(MY_EMAIL.."\r\n") 
       elseif(count == 3) then 
         conn:send(EMAIL_PASSWORD.."\r\n") 
         count = count + 1 
       elseif(count==4) then 
         count = count+1 
         conn:send("MAIL FROM:<" .. MY_EMAIL .. ">\r\n") 
       elseif(count==5) then 
         count = count+1 
         conn:send("RCPT TO:<" .. mail_to ..">\r\n") 
       elseif(count==6) then 
         count = count+1 
         conn:send("DATA\r\n") 
       elseif(count==7) then 
         count = count+1 
         local message = string.gsub( 
         "From: \"".. MY_EMAIL .."\"<"..MY_EMAIL..">\r\n" .. 
         "To: \"".. mail_to .. "\"<".. mail_to..">\r\n".. 
         "Subject: ".. email_subject .. "\r\n\r\n" .. 
         email_body,"\r\n.\r\n","") 
         conn:send(message.."\r\n.\r\n") 
       elseif(count==8) then 
         count = count+1 
          tmr.stop(0) 
          conn:send("QUIT\r\n") 
       else 
         conn:close() 
       end 
 end 
 -- The connectted() function is executed when the SMTP socket is connected to the SMTP server. 
 -- This function will create a timer to call the do_next function which will send the SMTP commands 
 -- in sequence, one by one, every 5000 seconds.   
 -- You can change the time to be smaller if that works for you, I used 5000ms just because. 
 function connected(conn) 
   print("Connected - Starting Timer") 
   tmr.alarm(0,2000,1,do_next) 
 end 
 -- @name send_email 
 -- @description Will initiated a socket connection to the SMTP server and trigger the connected() function 
 -- @param subject The email's subject 
 -- @param body The email's body 
 function send_email(subject,body) 
    count = 0 
    email_subject = subject 
    email_body = body 
    print ("Open Connection") 
    --conn = net.createConnection(net.TCP,1) 
    conn = tls.createConnection()
    conn:on("connection",connected) 
    conn:on("receive",display) 
    conn:connect(SMTP_PORT,SMTP_SERVER) 
 end 
 -- Send an email 
 print ("Sending started...") 
 send_email("ESP8266-GMailSender","Hi there!")
 

alexch25

New member
У кого-нибудь есть скрипт на lua для датчика напряжения и тока на ina219?
 

Tantrum

New member
Недавно библиотека ds18b20 перекочевала из C modules в Lua modules. Кто знает как с ней теперь работать? Если в наглую пытаться залить файл ds18b20.lua в esp8266, выводится сообщение "недостаточно памяти"
 
Сверху Снизу