Sub Process_Globals
Private TempSensorPin As Pin 'Output pin connected from the TMP36 sensor
Private TempSensorPinNumber As Byte = 0x00 'Pin number used is A0 (Analog)
Private d1 As D1Pins
Private timer1 As Timer
Private pin As Pin
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Private server As WiFiServerSocket
Private astream As AsyncStreams
Private ser As B4RSerializator
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
'Init the pin with TMP36 connected
TempSensorPin.Initialize(TempSensorPinNumber, TempSensorPin.MODE_OUTPUT)
Log("AppStart")
RunNative( "SetIP" , Null )' STATIC IP 192.168.1.6 ---> code #if C
'ACCESS POINT
If wifi.StartAccessPoint2("AccessPontESP","12345678") Then ' Router SSID e Passw.
Log("Connected Access Point")
Log("Module ESP-12 IP: ", wifi.LocalIp)
Else
Log("Failed to connect")
Return
End If
timer1.Initialize("timer1_Tick", 1000)
pin.Initialize(d1.D6, pin.MODE_INPUT)
timer1.Enabled=True
server.Initialize(80, "server_NewConnection")
server.Listen
End Sub
Sub Server_NewConnection (NewSocket As WiFiSocket)
Log("Client connected")
astream.Initialize(NewSocket.Stream, "astream_NewData", "astream_Error")
End Sub
Sub AStream_NewData (Buffer() As Byte)
Dim be(10) As Object 'used as a storage buffer.
Dim objects() As Object = ser.ConvertBytesToArray(Buffer, be)
Log("Recieved:")
For Each o As Object In objects
Log(o)
Next
'Log("Received: ", Buffer)
End Sub
Sub AStream_Error
Log("Error")
server.Listen
timer1.Enabled = False
End Sub
'STATIC IP (Replace with desired IP)
#if C
void SetIP(B4R::Object* o) {
IPAddress ip(192, 168, 1, 6); // (Replace with desired IP)
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
WiFi.config(ip, gateway, subnet);
}
#end if
Sub Timer1_Tick
astream.Write(ser.ConvertArrayToBytes(Array("Sent from ESP", Millis, TempSensorPin.AnalogRead, pin.DigitalRead)))
End Sub