HTTP GET request to a second board

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
ZKDMun
Posts: 42
Joined: Thu Nov 24, 2016 2:34 pm
Location: Hamburg

HTTP GET request to a second board

Post by ZKDMun » Thu Jan 19, 2017 9:16 pm

I have two ESP8266 flashed with MicroPython.

At the moment I try to get a connection between this boards - because later I will send information from one board to another one.

I read this two tutorials before:
https://docs.micropython.org/en/latest/ ... k_tcp.html
https://docs.micropython.org/en/latest/ ... asics.html

I have load the example of the "Simple HTTP server" on the board#1.
After the import the server seems to be active - open with the browser (192.168.4.1:80) I can see a table with the ESP8266 Pins and the values.
This part works perfect.

But I can not make a HTTP GET request with the board#2.

Code: Select all

>>> import network
>>> sta_if = network.WLAN(network.STA_IF)
>>> sta_if.connect("MicroPython-627bt1","micropythoN") ###board#1
>>> sta_if.isconnected()
True
>>> import socket
>>> s = socket.socket()
>>> ai = socket.getaddrinfo("192.168.4.1",80)
>>> addr = ai[0][-1]
>>> s.connect(addr)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 103] ECONNABORTED
>>>
__________________________________________
the REPL of the board#1 told me:

Code: Select all

client connected from ("192.168.4.3", 53807)
client connected from ("192.168.4.3", 53808)
edit: Forget this... it was from my webbrowser on my pc... nothing to do with the second board :/
_________________________________________[/color]

what is the meaning of "ECONNABORTED"...?
Is it possible to get information from another board with this method in generally?

(My vision is, that board#1 should be something like a measuring station, and board#2 should be connected with an lcd or something else which should show the information of board#1)

ZKDMun
Posts: 42
Joined: Thu Nov 24, 2016 2:34 pm
Location: Hamburg

Re: HTTP GET request to a second board

Post by ZKDMun » Fri Jan 20, 2017 3:51 pm

After a second ">>> s.connect(("192.168.4.1",80))" I got this:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 9] EBADF

ZKDMun
Posts: 42
Joined: Thu Nov 24, 2016 2:34 pm
Location: Hamburg

Re: HTTP GET request to a second board

Post by ZKDMun » Sun Jan 22, 2017 1:18 pm

Solved it!

It's better to set ap_if.active(False).
Or to change the IP address for the client module.
Because if not, and the two boards have the same IP adress, it seems that the socket didn't know to which board he have to connect... or something like that. Fact is: with ap_if.actice(False) I was able to connect and to receive the data... :oops:

Post Reply