B4R Question About ESP8266 - WiFi Remote Configuration

Cesar_Morisco

Active Member
About "ESP8266 - WiFi Remote Configuration" Everything is working I can send command from my PC to serial port of ESP8266.
But I can't Read the sensor that is connected to my arduino board that sends a command to the serial port of the ESP8266 to my PC. Someone tell me how to do it. I'm using this code for the first time.
 

teddybear

Well-Known Member
Licensed User
What kind of sensor do you use, how does it connect with you ESP?
 
Upvote 0

Cesar_Morisco

Active Member
HELLO
My sensor is a DS18B20 that is connected to my Arduino board that reads and sends it to the ESP8266 serial port 01
That sends to my pc via wifi .thanks
 
Upvote 0

teddybear

Well-Known Member
Licensed User
HELLO
My sensor is a DS18B20 that is connected to my Arduino board that reads and sends it to the ESP8266 serial port 01
That sends to my pc via wifi .thanks
1.Why not read the sensor with Esp8266 directly? here is a tutorial

2.Which protocol do you use that esp communicates with arduino
 
Last edited:
Upvote 0

Cesar_Morisco

Active Member
Hello everything is fine
You don't need to pay my postage and just say that WiFi Remote Configuration does not send data, it only receives data
I will understand
Thanks for the help
 
Upvote 0

Cesar_Morisco

Active Member
Hey guys
All good
About ESP8266 - WiFi Remote Configuration
I made some modifications
I'm already sending data via serial port using SerialCom.
The problem is that I can't receive data from the serial port and use the ip configuration in the browser, it crashes, someone to help me with this question, thank you

locking:
Private Sub Astream_NewData (Buffer() As Byte)
    
    AstreamCom_NewData(Buffer) '//////////////locking
 
  Log(Buffer)
    If bc.IndexOf(Buffer, "GET") <> -1 Then
        If bc.IndexOf(Buffer, "/set") <> -1 Then
            
            Dim ssid = "", password  = "" As String
            Dim i1 As Int = 0
            Dim i2 As Int = 0
            For Each b1() As Byte In bc.Split(Buffer, " ")
                If i1 = 1 Then
                    For Each b2() As Byte In bc.Split(b1, "/")
                        Select i2
                            Case 2
                                ssid = bc.StringFromBytes(b2)
                            Case 3
                                password = bc.StringFromBytes(b2)
                        End Select
                        i2 = i2 + 1
                    Next
                    
                End If
                i1 = i1 + 1
            Next
            Log(StackBufferUsage)
            Astream.Write("HTTP/1.1 200").Write(CRLF)
            Astream.Write("Content-Type: text/html").Write(CRLF).Write(CRLF)
            Astream.Write("<script>setTimeout(function(){location.href=""http://192.168.4.1""} , 20000);</script>")
            Astream.Write("WiFi set to: ").Write(ssid).Write(", password: ").Write(password).Write("<br/>Please wait...")
            Main.SaveNetworkDetails(ssid, password)
            CallSubPlus("ConnectWifi", 500, 0)
        Else If bc.IndexOf(Buffer, " / ") <> -1 Then
            Astream.Write("HTTP/1.1 200").Write(CRLF).Write(CRLF)
            If Main.WiFi.IsConnected Then
                Astream.Write("Connected to network.").Write(CRLF)
                Astream.Write("ESP8266 IP address: ").Write(Main.WiFi.LocalIp)
                
                
                Else
                Astream.Write("Not connected!")
            End If
        Else
            Astream.Write("HTTP/1.1 404").Write(CRLF)
        End If
        CallSubPlus("CloseConnection", 200, 0)
    End If
    
End Sub
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Hey guys
All good
About ESP8266 - WiFi Remote Configuration
I made some modifications
I'm already sending data via serial port using SerialCom.
The problem is that I can't receive data from the serial port and use the ip configuration in the browser, it crashes, someone to help me with this question, thank you
The code is a webserver which is used for wifi remote configuration, it communicates with a client using TCP/IP, it is the irrelevant to the serial port.
I do not understant your question, you'd better post a schematic diagram to describe it
 
Upvote 0

Cesar_Morisco

Active Member
Hello
Practically the same as this picture.
The ESP8266 01 send and receive data from my PC
The ARDUINO sends and receives data ESP8266 01
Via IP PORT TCP Socket
THANKS
maxresdefault.jpg
 
Upvote 0

teddybear

Well-Known Member
Licensed User
1.The ESP8266 01 send and receive data from my PC
I guess that you do something via wifi
2.The ARDUINO sends and receives data ESP8266 01 Via IP PORT TCP Socket
You connect esp01 with arduino using serial port , I guess that the communication is UART Protocol.

I guess your question is that PC sends data to Esp01 via wifi, and then Arduino reads data from esp01 by uart,finally PC reads the message which PC send to esp01 from arduino by usb. is it?
You'd better posting a project or code
 
Last edited:
Upvote 0

Cesar_Morisco

Active Member
Hello everything is fine
Dude and that's right
All communication and on wifi
do you have to help me or give me an example how to do it
Thank you already
here in the code:
here in the code
i am getting normal data with the esp8266 with wifi

I can't send from arduino to esp8266 with wifi
 for pc does not work

SerialCom.Initialize(9600,2,0)
    astreamCom.Initialize(SerialCom.Stream,"AstreamCom_NewData", "AstreamCom_Error")

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Astream.Initialize(NewSocket.Stream,"Astream_NewData", "Astream_Error")
    Astream.WaitForMoreDataDelay = 200
    Astream.MaxBufferSize = 100
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Sub Astream_Data(data() As Byte)
    Log("Send Serial Data to Wifi")
    Astream.Write(data)
End Sub
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Sub AstreamCom_NewData(Buffer() As Byte)
    If server.Socket.Connected Then
        Astream.Write(Buffer)
        Log(Buffer)
    End If
End Sub
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Sub AstreamCom_Data(data() As Byte)
    astreamCom.Write(data)
End Sub

Sub astreamCom_Error
    'Log("error")
End Sub


Private Sub ConnectWifi(u As Byte)
    Main.ConnectToNetwork
End Sub

Private Sub CloseConnection(u As Byte)
    Log("close connection")
    If server.Socket.Connected Then
        server.Socket.Stream.Flush
        server.Socket.Close
    End If
End Sub

Private Sub AStream_Error
    Log("Disconnected")
    server.Listen
End Sub
 
Upvote 0

Cesar_Morisco

Active Member
Hello everything is fine
About ESPConfigureWiFi is already
it worked very well to receive data from my PC I can't send data via IP Port
Does anyone have a clue or a tip to solve this problem. Can I use another port or esp8266 a tip please
Thanks
 
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
About "ESP8266 - WiFi Remote Configuration" Everything is working I can send command from my PC to serial port of ESP8266.
But I can't Read the sensor that is connected to my arduino board that sends a command to the serial port of the ESP8266 to my PC. Someone tell me how to do it. I'm using this code for the first time.
1) are you sure the arduino and DS18B20 sensor read the temperature and send it?
2) where is the log in Astream_NewData (Buffer() As Byte) that you received the temperature?
 
Upvote 0

Cesar_Morisco

Active Member
Hello, thanks
For the answer Yes, my arduino board is reading the ds18b20 and it is sent to the RX of the ESP8266
I can see in serial terminal
I can't see it in my SocketTest on PC It doesn't appear
But if I send SocketTest command to my arduino board I can turn on and off my relay that is connected on my arduino board too
 

Attachments

  • Sem título.png
    Sem título.png
    58.1 KB · Views: 119
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
I can't see it in my SocketTest on PC It doesn't appear
It would be better for users who want to help you if you attached the complete project.
From the little code I see in the posts, it seems that there is a problem with the usart serial.
I don't want to be wrong but it seems to me that arduino sends a string in the serial in text format,
while esp would like it in bytes. So you would also need to use the serializator lib.
 
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
here it works, I just added
B4X:
   WiFiServer.Astream.Initialize(Serial1.Stream, "Astream_NewData", Null)
Note:
If you use arduino to program the esp, you will have Arduino TX -->TX Esp-01
Remember:
after programming the esp, you have to reverse the connections to receive the temperature of the 18B20
(Arduino TX ----> RX ESP-01)
 
Last edited:
Upvote 0

Cesar_Morisco

Active Member
Thanks for the answer
Have to do this. To see the configuration web I don't receive the data in the TCP terminal
I see it in the serial. And I no longer have the command to send data from the TCP terminal to esp8266
I thank
timer1:
timer1.Initialize("timer1_Tick", 5000)
    End Sub

Private Sub Server_NewConnection (NewSocket As WiFiSocket)
    Astream.Initialize(NewSocket.Stream,"Astream_NewData", "Astream_Error")
    Astream.WaitForMoreDataDelay = 200
    Astream.MaxBufferSize = 100
    timer1.Enabled = True
End Sub

Sub Timer1_Tick
    Astream.Initialize(Main.Serial1.Stream, "Astream_NewData", Null)'<---------------i just added this line'
End Sub
 
Upvote 0

Cesar_Morisco

Active Member
Hello XorAndOr how are you
About this issue of receiving data from the sensor ds18b20 and I'm having this problem I can't see the temperature data in the TCP Terminal
About this code that you gave me, it uses the same TX output of the ESP8266 Right I don't know what I'm doing wrong, I don't see the data.
thank you for your help peace
Astream.Initialize:
Private Sub Server_NewConnection (NewSocket As WiFiSocket)
    Astream.Initialize(NewSocket.Stream,"Astream_NewData", "Astream_Error")
    Astream.WaitForMoreDataDelay = 200
    Astream.MaxBufferSize = 100
    timer1.Enabled = True
End Sub

Sub Timer1_Tick
    Astream.Initialize(Main.Serial1.Stream, "Astream_NewData", Null)'<---------------i just added this line'
End Sub

Private Sub Astream_NewData (Buffer() As Byte)
    Log(Buffer)
    If bc.IndexOf(Buffer, "GET") <> -1 Then
        If bc.IndexOf(Buffer, "/set") <> -1 Then
            Dim ssid = "", password  = "" As String
            Dim i1 As Int = 0
            Dim i2 As Int = 0
            For Each b1() As Byte In bc.Split(Buffer, " ")
                If i1 = 1 Then
                    For Each b2() As Byte In bc.Split(b1, "/")
                        Select i2
                            Case 2
                                ssid = bc.StringFromBytes(b2)
                            Case 3
                                password = bc.StringFromBytes(b2)
                        End Select
                        i2 = i2 + 1
                    Next
                    
                End If
                i1 = i1 + 1
            Next
            Log(StackBufferUsage)
            Astream.Write("HTTP/1.1 200").Write(CRLF)
            Astream.Write("Content-Type: text/html").Write(CRLF).Write(CRLF)
            Astream.Write("<script>setTimeout(function(){location.href=""http://192.168.4.1""} , 20000);</script>")
            Astream.Write("WiFi set to: ").Write(ssid).Write(", password: ").Write(password).Write("<br/>Please wait...")
            Main.SaveNetworkDetails(ssid, password)
            CallSubPlus("ConnectWifi", 500, 0)
        Else If bc.IndexOf(Buffer, " / ") <> -1 Then
            Astream.Write("HTTP/1.1 200").Write(CRLF).Write(CRLF)
            If Main.WiFi.IsConnected Then
                Astream.Write("Connected to network.").Write(CRLF)
                Astream.Write("ESP8266 IP address: ").Write(Main.WiFi.LocalIp)
                Else
                Astream.Write("Not connected!")
            End If
        Else
            Astream.Write("HTTP/1.1 404").Write(CRLF)
        End If
        CallSubPlus("CloseConnection", 200, 0)
    End If
    End Sub

Sub Astream_Data(data() As Byte)
    Astream.Write(data)
    End Sub

Private Sub AStream_Error
    Log("Disconnected")
    server.Listen
    timer1.Enabled = False
End Sub


Private Sub ConnectWifi(u As Byte)
    Main.ConnectToNetwork
End Sub

Private Sub CloseConnection(u As Byte)
    Log("close connection")
    If server.Socket.Connected Then
        server.Socket.Stream.Flush
        server.Socket.Close
    End If
End Sub
 
Upvote 0
Top