Chat freely about anything...

User avatar
By hajo
#56479 I would like to realize a communication of two ESP8266 between each other via sending URL-Messages which are cought by the other ESP via msgget. If I write something like http://192.168.7.5/msg?switch=0 into my browsers adress-line, it works, but i now like to make my ESP send the http... unfortunately I've got no idea how to realize this in ESPbasic.

Thanks for helping,

Hajo
User avatar
By ChrisH
#56598 (NB: I haven't used ESPBasic, I just cheked the docs).

It seems that ESPbasic doesn't have a built in function for sending a GET(/"send") request. BUT, GET request are not that complicated and you could use the Telnet functions to accomplish it.

The simplest GET request you can do (by HTTP definitions) looks like this:
Code: Select allGET / HTTP/1.0
Host: 192.168.1.1


(It needs to end with two new lines (one empty line..)
The value of Host doesn't really matter (and depending on the implementation of the HTTP protocol, you could, potentially, skip it)

(Normally, I would advice not to use HTTP in a case like this, but ESPBasic doesn't have much in ways of communication over the network).

It could look something like this:
Code: Select allTn = telnet.client.connect(“192.168.7.5”, 80)
telnet.client.write(“GET /msg?switch=0 HTTP/1.1\r\n”)
telnet.client.write(“Host: 192.168.7.6\r\n”)
telnet.client.write(“\r\n”)

(NOT tested/verified!)

Also, I just saw that there is a specific forum for ESPbasic, so you should try to ask there!
viewforum.php?f=40

ADDITION, there is a wget function you can use:

Code: Select allwget("192.168.7.5/msg?switch=0")

See: viewtopic.php?f=40&t=7267
User avatar
By Mmiscool
#56600 The wget() function is probably your best bet.

It works and there a few examples here on the forum.
User avatar
By octether
#57703
Mmiscool wrote:The wget() function is probably your best bet.

It works and there a few examples here on the forum.


I want to control a Philips Hue bridge and for this I have to issue /PUT-reqests.
From the sources I figure that wget() only can do /Get for now, so
I tried to assemble a /PUT-request very much like in the example above.

A request should be asserted like
Code: Select allPUT /api/kxleZtGgugq8zkM8C21HSh4Cm5bv2Cqq0UzJ3VkW/lights/5/state HTTP/1.1
Content-Length: 12

{"on":true}

"
, but somehow I fail to assert the proper newline characters.
"telnet.client.write(“\r\n”)" puts it out as literal, adding strings together with chr(13)&chr(10)
also yielded no results.

Can anyone give me a tip here?
P.S. this is an offtopic question, yet the example in this thread exactly fits my problem.
Since I'm a newbie here, I'm just unsure if making my problem a new topic would be encouraged.