edited: connecting to www was added.
B4J app for testing and setting ESP8266/32 using AT Commands.
AT commands are used to test the module, set baud rate, check version, set RF power etc. The app also connects to a router. List of AT commands can be downloaded from here:
https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf
https://docs.espressif.com/projects/esp-at/en/latest/AT_Command_Set/index.html
A new board comes with AT commands firmware, after uploading your code the AT commands are replaced. To have the AT commands back you need to upload the factory bin file.
The module is connected via USB, or via USB to Serial adapter, or via Arduino.
B4J app for testing and setting ESP8266/32 using AT Commands.
AT commands are used to test the module, set baud rate, check version, set RF power etc. The app also connects to a router. List of AT commands can be downloaded from here:
https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf
https://docs.espressif.com/projects/esp-at/en/latest/AT_Command_Set/index.html
A new board comes with AT commands firmware, after uploading your code the AT commands are replaced. To have the AT commands back you need to upload the factory bin file.
The module is connected via USB, or via USB to Serial adapter, or via Arduino.
B4X:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private sp As Serial
Private astream As AsyncStreams
Private cmb1 As ComboBox
Private Label1 As Label
Private text1 As TextArea
Private btnClear As Button
Private btnSend As Button
Private rate As Int = 115200
Private txt1 As TextField
Private TextField1 As TextField
Private Button1 As Button
Private TextField2 As TextField
Private Button2 As Button
Private TextField3 As TextField
Private Button3 As Button
Private TextField4 As TextField
Private cmbBaud As ComboBox
Private btnCmnd As Button
Private cmbCmnd As ComboBox
Private TextField5 As TextField
Private txtIP As TextField
Private btnWeb As Button
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
sp.Initialize("")
cmb1.Items.AddAll(sp.ListPorts)
cmbBaud.Items.AddAll(Array As String("9600", "38400", "115200"))
cmbCmnd.Items.AddAll(Array As String("AT+RST", "AT+SLEEP", "AT+RFPOWER","AT+UART_CUR","AT+UART_CUR=115200,8,1,0,1", _
"AT+SYSRAM","AT+SYSADC","AT+CIPSTA_CUR"))
End Sub
Sub cmb1_SelectedIndexChanged(Index As Int, Value As Object)
Try
sp.Open(cmb1.Value)
sp.SetParams(rate,8,1,0)
astream.Initialize(sp.GetInputStream, sp.GetOutputStream, "astream")
Label1.Text = "Port Opened"
Catch
Label1.Text = "Port is busy"
Log("Port error")
End Try
End Sub
Sub cmbBaud_SelectedIndexChanged(Index As Int, Value As Object)
rate=cmbBaud.Value
cmb1.Enabled=True
End Sub
Sub cmbCmnd_SelectedIndexChanged(Index As Int, Value As Object)
btnCmnd.Enabled=True
End Sub
Sub btnCmnd_Click
Dim command As String
command=cmbCmnd.Value & Chr(13) & Chr(10)
astream.Write(command.GetBytes("UTF8"))
End Sub
Sub btnSend_Action
Dim str As String = txt1.Text.ToUpperCase & Chr(13) & Chr(10)
astream.Write(str.GetBytes("UTF8"))
End Sub
Sub Button1_Click
Dim str1 As String = TextField1.Text.ToUpperCase & Chr(13) & Chr(10)
astream.Write(str1.GetBytes("UTF8"))
End Sub
Sub Button2_Click
Dim str2 As String = TextField2.Text.ToUpperCase & Chr(13) & Chr(10)
astream.Write(str2.GetBytes("UTF8"))
End Sub
Sub Button3_Click
Dim str3 As String = "AT+CWMODE=1" & Chr(13) & Chr(10)
astream.Write(str3.GetBytes("UTF8"))
Sleep(1000)
Dim str4 As String = "AT+CWJAP=" & TextField4.Text & "," & TextField5.text & Chr(13) & Chr(10)
astream.Write(str4.GetBytes("UTF8"))
Sleep(2000)
btnWeb.Enabled=True
End Sub
Sub btnWeb_Click
Dim str3 As String = "AT+CIPSTART=" & Chr(0x22) & "TCP" & Chr(0x22) & "," & Chr(0x22) & txtIP.text & Chr(0x22) & "," & "80" & Chr(13) & Chr(10)
Dim str6 As String = "Host: " & txtIP.text & Chr(13) & Chr(10) & Chr(13) & Chr(10)
Dim bts As Int = str6.Length + 16
astream.Write(str3.GetBytes("UTF8"))
Sleep(1000)
Dim str4 As String = "AT+CIPSEND=" & bts & Chr(13) & Chr(10)
astream.Write(str4.GetBytes("UTF8"))
Sleep(1000)
Dim str5 As String = "GET / HTTP/1.1" & Chr(13) & Chr(10)
astream.Write(str5.GetBytes("UTF8"))
astream.Write(str6.GetBytes("UTF8"))
End Sub
Sub btnClear_Click
text1.Text=""
End Sub
Sub MainForm_Closed
'sp.Close
End Sub
Sub AStream_NewData (Buffer() As Byte)
text1.Text=text1.Text & BytesToString(Buffer,0,Buffer.Length,"UTF-8")
End Sub
Attachments
Last edited: