#Region Project Attributes
#AutoFlushLogs : True
#CheckArrayBounds : True
#StackBufferSize : 1024
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Public Ts As Timer
Public Segundo As Byte = 0
Public Minuto As Byte = 0
Public Hora As Byte = 0
Public bc As ByteConverter
Public Maniobras As UInt = 0
Public Horas_Uso As UInt = 0
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("****************************")
Log("Inicia Aplicacion")
Ts.Initialize("Ts_Tick",1000)
Ts.Enabled = True
Conecta_Wifi(0)
End Sub
Sub Ts_Tick
Segundo = Segundo + 1
Horas_Uso = Horas_Uso + 1
If Segundo > 59 Then
Segundo = 0
Minuto = Minuto + 1
If Minuto > 59 Then
Minuto = 0
Hora = Hora + 1
If Hora > 23 Then
Hora = 0
End If
End If
End If
End Sub
Sub Conecta_Wifi(Nada As Byte)
Log("Intentando conectar a la red WIFI")
wifi.Disconnect
wifi.ConnectAsync("xxx", "xxx", 0, Null, "wifi_Connected")
End Sub
Sub WiFi_Connected (Success As Boolean)
If Success = True Then
Log("WIFI Conectada !!!")
Log("La IP es: ",wifi.LocalIp)
Else
Log("No conectado la WIFI, se reintenta")
CallSubPlus("Conecta_Wifi",5000,0)
End If
If Success = True Then
HttpJob.Initialize("Paso_000")
Envia_Estado(0)
End If
End Sub
'
' Envia Estados de la Tarjeta de Control.
' Envia Datos al servidor
' Numero de Serie -> 5 Digitos -> 00000
' Fecha en el ESP32 -> 8 Caracteres -> dd/mm/aa
' Hora en el Servidor -> 8 Caracteres -> hh:mm:ss
' Version Hardware -> -> 4.12.00
' Version Software -> -> 4.12.26a
' Año de Fabricacion -> 4 Digitos -> 2024
' Mes de Fabricacion -> 2 Digitos -> 01
' Numero de Maniobras -> 10 Digitos -> 0000000000
Sub Envia_Estado(Nada As Byte)
Dim Ti As ULong = 0
Dim Amo As Int = 2024
Dim Mes As Int = 1
Dim Numero_Serie As Int = 20
Log("*******************************")
Log("Inicia Envio ... Buffer Utilizado = ",StackBufferUsage )
Dim P0() As Byte = "&".GetBytes
Dim P1() As Byte = JoinBytes(Array ("Amo=".GetBytes,NumberFormat(Amo,4,0).GetBytes))
Dim P2() As Byte = JoinBytes(Array ("Mes=".GetBytes,NumberFormat(Mes,2,0).GetBytes))
Dim P3() As Byte = JoinBytes(Array ("Numero_de_Serie=".GetBytes,NumberFormat(Numero_Serie,5,0).GetBytes))
Dim P4() As Byte = "Fecha=01/01/2024".GetBytes
Dim P5() As Byte = JoinBytes(Array ("Hora=".GetBytes,NumberFormat(Hora,2,0).GetBytes,":".GetBytes,NumberFormat(Minuto,2,0).GetBytes,":".GetBytes,NumberFormat(Segundo,2,0).GetBytes))
Dim P6() As Byte = "Version_H=4.12.00".GetBytes
Dim P7() As Byte = "Version_S=4.12.26a".GetBytes
Maniobras = Maniobras + 1
Dim P8() As Byte = JoinBytes(Array ("Maniobras=".GetBytes,NumberFormat(Maniobras,8,0).GetBytes))
Dim P9() As Byte = JoinBytes(Array ("Horas_Uso=".GetBytes,NumberFormat(Horas_Uso,8,0).GetBytes))
Dim P10() As Byte = JoinBytes(Array (P1,P0,P2,P0,P3,P0,P4,P0,P5,P0,P6,P0,P7,P0,P8,P0,P9))
'Log("Envia ->",bc.StringFromBytes(P9))
Ti = Micros
Envia_Post(P10)
Ti = Micros - Ti
Log("Tiempo Invertido = ",Ti / 1000, " Maniobra = ",Maniobras)
End Sub
'
'
Sub Envia_Post(E() As Byte)
HttpJob.AddHeader("Content-Type", "application/x-www-form-urlencoded")
HttpJob.Post("
https://ota-puerta.000webhostapp.com/?key1=value1",E)
End Sub
Sub JobDone (Job As JobResult)
Log("Nombre del Paso : ", Job.JobName)
Log("*******************************")
If Job.Success Then
'Log("Response: ", bc.SubString2(Job.Response, 0, Min(20, Job.Response.Length))) ' Limita a 20 Caracteres
If Job.JobName = "Paso_000" Then
CallSubPlus("Envia_Estado",10000,0)
'HttpJob.Initialize("Paso_001") '
'Log("Cambio a Paso_001")
End If
Else
CallSubPlus("Envia_Estado",5000,0)
Log("++++++ ERROR +++++")
Log("ErrorMessage: ", Job.ErrorMessage)
Log("Status: ", Job.Status)
'Log(Job.Response)
End If
End Sub