wemos d1 mini

Spazio dedicato agli utenti Italiani
Post Reply
Giuseppe
Posts: 14
Joined: Sun Jul 11, 2021 9:56 am
Been thanked: 4 times

wemos d1 mini

Post by Giuseppe »

Salve a tutti . Stò utilizzando questo programma per gestire 8 uscite con il wemos d1.
Il tutto funziona perfettamente , sia attivazione uscite singole che totali con telegram .
Il problema si è presentato con una segnalazione tramite led di disconnessione wi-fi
Il led che mi segnala la connessione e la disconnessione è out9. Funziona solo per la segnalazione avvenuta connessione
Come potrei risolvere il problema grazie in anticipo a tutti

Code: [Local Link Removed for Guests]

' Inizio programma
' define the variables that are used for the output pins
out1 = 0  'set initial logic value of check boxes and output pin
out2 = 0  'set initial logic value of check boxes and output pin
out3 = 0  'set initial logic value of check boxes and output pin
out4 = 0  'set initial logic value of check boxes and output pin
out5 = 0  'set initial logic value of check boxes and output pin
out6 = 0  'set initial logic value of check boxes and output pin
out7 = 0  'set initial logic value of check boxes and output pin
out8 = 0  'set initial logic value of check boxes and output pin
out9 = 0  'led wifi

'-------------------------------------------------
A1 = 16 'D0 modulo
A2 = 14 'D5 modulo
A3 = 12 'D6 modulo
A4 = 13 'D7 modulo
A5 = 15 'D4 modulo
A6 = 2  'D3 modulo ha il led integrato sul modulo
A7 = 0  'D2 modulo
A8 = 4  'D1 modulo
A9 = 5 '
'-------------------------------------------------
Pin.MODE A9, Output  'define pin wifi led
Pin.MODE A1, Output  'define pin mode
Pin.MODE A2, Output  'define pin mode
Pin.MODE A3, Output  'define pin mode
Pin.MODE A4, Output  'define pin mode
Pin.MODE A5, Output  'define pin mode
Pin.MODE A6, Output  'define pin mode
Pin.MODE A7, Output  'define pin mode
Pin.MODE A8, Output  'define pin mode

'----------------------------------------------------------------
GoSub control_wifi

GoSub lblPinOutSet 'set pin out at initial valuue
RcvdTxt$ = ""   'Received text extract from receivet telegram message
MsgToTLGM$ = ""  'Message to transmit to Telegram
token$ = "inserire token"  'BOT token keep confidential
c$ = "inserire nome bot" 'chat id
telegram.settoken token$  'set telegram token ID
telegram.setwait 10   'set the max time for answer from TG server
wlog "-telegram.getMe ----", time$
wlog telegram.getMe$ 'get the user?s informations
wlog "--------------------"


timer0 5000, lblGetTGmessage  'Receive the messages from telegram at 5s interval
Wait

'-----------------------------------------------------------------

lblGetTGmessage: 'Receive the messages from telegram

'if WIFI.STATUS <> 3 then out9 = 0 'se il wifi non è presente led wifi = 0
'if WIFI.STATUS = 3 then out9 = 1  'il wifi è collegato accendo il led wifi
GoSub control_wifi

r$ = telegram.getUpdates$ 'get the new messages
wlog "-getUpdate -----------------", time$
wlog r$
wlog "--------------------------------------"
RcvdTxt$ = json$(r$, "text") 'get text field
If (RcvdTxt$ = "not found") Then Return
 'c$ = json$(r$, "from.id")   'get the chat_id
  c$ = json$(r$, "from.chat.id")   'get the chat_id correct
'  c= val(c$)      'problemi di conversione numeri >32bit
  'wlog telegram.sendmessage$(c,"echo : " + RcvdTxt$) 
wlog "-received text field -----------------"
wlog RcvdTxt$
wlog "--------------------------------------"


'================= MANAGE RECEIVED COMMANDS FROM TELEGRAM ====================
lblManageTGCommands:
If RcvdTxt$ = "/update" Then  GoTo lblReadPinStatus  'jump, return  output pin logical level and create response to telegram
If RcvdTxt$ = "/Toggle_A1" Then  out1 = 1 - out1 : GoSub lblPinOutSet  'toggle out1  'set/update pin out at variables value
If RcvdTxt$ = "/Toggle_A2" Then  out2 = 1 - out2 : GoSub lblPinOutSet  'toggle out2  'set/update pin out at variables value
If RcvdTxt$ = "/Toggle_A3" Then  out3 = 1 - out3 : GoSub lblPinOutSet  'toggle out3  'set/update pin out at variables value
If RcvdTxt$ = "/Toggle_A4" Then  out4 = 1 - out4 : GoSub lblPinOutSet  'toggle out4  'set/update pin out at variables value

If RcvdTxt$ = "/Toggle_A5" Then  out5 = 1 - out5 : GoSub lblPinOutSet  'toggle out5  'set/update pin out at variables value
If RcvdTxt$ = "/Toggle_A6" Then  out6 = 1 - out6 : GoSub lblPinOutSet  'toggle out6  'set/update pin out at variables value
If RcvdTxt$ = "/Toggle_A7" Then  out7 = 1 - out7 : GoSub lblPinOutSet  'toggle out7  'set/update pin out at variables value
If RcvdTxt$ = "/Toggle_A8" Then  out8 = 1 - out8 : GoSub lblPinOutSet  'toggle out8  'set/update pin out at variables value


If RcvdTxt$ = "/Uscite_On" Then out1=1:out2=1:out3=1:out4=1:out5=1:out6=1:out7=1:out8=1 :GoSub lblPinOutSet  
 
'all out set 1 'set/update pin out at variables value 
 

If RcvdTxt$ = "/Uscite_Off" Then out1=0:out2=0:out3=0:out4=0:out5=0:out6=0:out7=0:out8=0 : GoSub lblPinOutSet 
 
  'all out set 1 'set/update pin out at variables value

'======== return  output pin logical level and create response to bot =========
lblReadPinStatus:
' %0A means line feed carriage return
' text from character "/" (included) is a command for bot
MsgToTLGM$ = "---   STATO USCITE   ---%0A%0A" 

If Pin(A1) = 1 Then
 MsgToTLGM$ = MsgToTLGM$ + "A1=ON  clicK or tap here to /Toggle_A1"
Else
 MsgToTLGM$ = MsgToTLGM$ + "A1=OFF clicK or tap here to /Toggle_A1"
End If
MsgToTLGM$ = MsgToTLGM$ + "%0A%0A" 'LF CR LF CR

If Pin(A2) = 1 Then
 MsgToTLGM$ = MsgToTLGM$ + "A2=ON  clicK or tap here to /Toggle_A2"
Else
 MsgToTLGM$ = MsgToTLGM$ + "A2=OFF clicK or tap here to /Toggle_A2"
End If
MsgToTLGM$ = MsgToTLGM$ + "%0A%0A" 'LF CR LF CR

If Pin(A3) = 1 Then
 MsgToTLGM$ = MsgToTLGM$ + "A3=ON  clicK or tap here to /Toggle_A3"
Else
 MsgToTLGM$ = MsgToTLGM$ + "A3=OFF clicK or tap here to /Toggle_A3"
End If
MsgToTLGM$ = MsgToTLGM$ + "%0A%0A" 'LF CR LF CR

If Pin(A4) = 1 Then
 MsgToTLGM$ = MsgToTLGM$ + "A4=ON  clicK or tap here to /Toggle_A4"
Else
 MsgToTLGM$ = MsgToTLGM$ + "A4=OFF clicK or tap here to /Toggle_A4"
End If

MsgToTLGM$ = MsgToTLGM$ + "%0A%0A" 'LF CR LF CR

If Pin(A5) = 1 Then
 MsgToTLGM$ = MsgToTLGM$ + "A5=ON  clicK or tap here to /Toggle_A5"
Else
 MsgToTLGM$ = MsgToTLGM$ + "A5=OFF clicK or tap here to /Toggle_A5"
End If
MsgToTLGM$ = MsgToTLGM$ + "%0A%0A" 'LF CR LF CR

If Pin(A6) = 1 Then
 MsgToTLGM$ = MsgToTLGM$ + "A6=ON  clicK or tap here to /Toggle_A6"
Else
 MsgToTLGM$ = MsgToTLGM$ + "A6=OFF clicK or tap here to /Toggle_A6"
End If
MsgToTLGM$ = MsgToTLGM$ + "%0A%0A" 'LF CR LF CR

If Pin(A7) = 1 Then
 MsgToTLGM$ = MsgToTLGM$ + "A7=ON  clicK or tap here to /Toggle_A7"
Else
 MsgToTLGM$ = MsgToTLGM$ + "A7=OFF clicK or tap here to /Toggle_A7"
End If
MsgToTLGM$ = MsgToTLGM$ + "%0A%0A" 'LF CR LF CR

If Pin(A8) = 1 Then
 MsgToTLGM$ = MsgToTLGM$ + "A8=ON  clicK or tap here to /Toggle_A8"
Else
 MsgToTLGM$ = MsgToTLGM$ + "A8=OFF clicK or tap here to /Toggle_A8"
End If


MsgToTLGM$ = MsgToTLGM$ + "%0A%0A%0A" 'LF CR LF CR LF CR LF CR
MsgToTLGM$ = MsgToTLGM$ + "Click or tap here to /Uscite_On"
MsgToTLGM$ = MsgToTLGM$ + "%0A%0A" 'LF CR LF CR
MsgToTLGM$ = MsgToTLGM$ + "Click or tap here to /Uscite_Off"
MsgToTLGM$ = MsgToTLGM$ + "%0A%0A" 'LF CR LF CR
MsgToTLGM$ = MsgToTLGM$ + "Click or tap here to /Aggiorna"

'=============== Send a text message to telegram ======================
lblSendTGmessage:
 wlog "-SendTGmessage -----------------", time$
  If c$ < " " Then wlog "c$=nul":Return 'return if chat id not valid
 'wlog telegram.sendmessage$(val(c$), "echo : " + text$)  'val(c$) not work properly
 wlog wget$("https://api.telegram.org/bot"+token$+"/sendMessage?chat_id="+c$+"&text="+ MsgToTLGM$)
wlog "---------------------------------"
Return

'---------------------------------------------------
lblPinOutSet:  'set output pin at logical level
Pin(A1) = out1
Pin(A2) = out2
Pin(A3) = out3
Pin(A4) = out4
Pin(A5) = out5
Pin(A6) = out6
Pin(A7) = out7
Pin(A8) = out8
Pin(A9) = out9
Return

control_wifi:
While WIFI.STATUS <> 3
  wlog "."
  pause 500 
Wend
wlog wifi.STATUS 

If WIFI.STATUS = 3 Then 
  out9 = 1 : 
  Else 
  out9 = 0 'il wifi è 
EndIf
Return
User avatar
cicciocb
Site Admin
Posts: 2063
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1361 times
Contact:

Re: wemos d1 mini

Post by cicciocb »

Secondo me puoi rimuovere tutti i

Code: [Local Link Removed for Guests]

GoSub lblPinOutSet
e metterne uno soltanto nel punto dove c'é il triangolo rosso
image.png
togli anche il : alla linea 198
You do not have the required permissions to view the files attached to this post.
Giuseppe
Posts: 14
Joined: Sun Jul 11, 2021 9:56 am
Been thanked: 4 times

Re: wemos d1 mini

Post by Giuseppe »

Giusto Cicciocb
Adesso provo e vediamo come và
Grazie ancora
MarioL
Posts: 21
Joined: Sun Mar 21, 2021 8:38 am
Has thanked: 258 times
Been thanked: 35 times

Re: wemos d1 mini

Post by MarioL »

Se ho ben capito, il loop while-wend non disattiva il led, prova ad invertire le verifiche in questo modo:

control_wifi:
if WIFI.STATUS = 3 Then
out9 = 1
Else
out9 = 0 'il wifi è
EndIf

' quindi assicurati che l'uscita sia aggiornata con
GoSub lblPinOutSet

While WIFI.STATUS <> 3
wlog "."
pause 500
Wend
wlog wifi.STATUS
Return
Giuseppe
Posts: 14
Joined: Sun Jul 11, 2021 9:56 am
Been thanked: 4 times

Re: wemos d1 mini

Post by Giuseppe »

Perfetto problema risolto grazie Cicciocb e grazie anche a MarioL
Post Reply