The use of the ESP8266 in the world of IoT

User avatar
By kr3ativ
#93741 Hello I want send data with this code
Code: Select allimport board
import busio
import time
import digitalio

y=busio.UART(board.TX, board.RX, baudrate=115200)
LED = digitalio.DigitalInOut(board.D13)
LED.direction = digitalio.Direction.OUTPUT

y.write(b'AT\r\n')
time.sleep(1)
print(y.read())

LED.value = True

y.write(b"AT+CWMODE=3\r\n") #trecem modulul in  modul wifi
time.sleep(1)
print(y.read())

y.write(b"AT+CWLAP\r\n") #cautam adresele vizibile
time.sleep(1)
print(y.read())


y.write(b'AT+CWJAP="test","12345678"'+b"\r\n") #ne contectam la adresa
time.sleep(3)
print(y.read())

y.write(b'AT+CIFSR\r\n') #IP
time.sleep(1)
print(y.read())

lat=1
lon=2
v=3
tp=5
hu=6
ps=5
gas=14
alt=0

print('\n')
y.write(b'GET http://licenta2022.000webhostapp.com/data.php?lat="+str(lat)+"&lng="+str(lon)+"&Vbat="+str(v)+"&temp="+str(tp)+"&umid="+str(hu)+"&pres="+str(ps)+"&rgas="+str(gas)+"&alt="+str(alt)'
                +b' HTTP/1.1\r\n'
                + b'Host: licenta2022.000webhostapp.com'
                + b'\r\n'+b'Connection: close\r\n\r\n')
time.sleep(1)
print(y.read())
time.sleep(1)


But when it is send GET string, I receive an error...
User avatar
By btidey
#93752 There is not a lot to go on here so most of this is guesswork.

1) The code looks like it is sending AT+ commands to an ESP8266 module running the basic AT+ firmware.

If so then it would be useful to know what is the processor environment that is sending commands.

2) The code seems to print out various bits of diagnostic messages from AT+ command s but also tries to connect to a local network using the AT+CWJAP command. I assume you are using the actual ssid and passwords rather than the dummy values shown.

3) It is possible to send commands to a web site using the AT+ command set but not how you are doing it.

You need to form a cmd string including the GET website url and protocol (HTTP/1.1)

Then you need to use the AT+CIPSEND=4 to send the length of the cmd string + 4 followed by the cmd string itself.

See the AT+ command set example pdf document for more details.

The other question to ask is why you are using the AT+ command set as the esp8266 firmware. Many people abandon this and build ESP8266 firmware to really utilise the power of the esp8266 as a general purpose microcomputer with wifi capabilities. In many cases this can take over the role of the parent processor which would be sending AT+ commands.