As the title says... Chat on...

User avatar
By Feilim Breatnach
#10449 Hi all, I've just recently started trying some basics with the ESP8266 and NodeMCU firmware. I was wondering if anyone has successfully performed an HTTP POST request and might have a code snippet of same.

I am hoping to try a Pushover Notification from the module (see https://pushover.net/api#messages). The API uses HTTPS and I have read on this forum that there are currently some issues with SSL support, and that it may have worked on an older firmware from ate January. In any case, just supposing that the API message post was standard HTTP I was wondering if anyone might have tried a HTTP POST to a similar JSON based API.

I've looked at some snippets relating to Thingspeak, but the API they expose uses HTTP GET requests...

Any help appreciated!
User avatar
By ribs99
#11414 I've been playing with the ESP8266 and the following code should help you get started. Just replace the token and user with your own and run the code. It should send you message from the ESP8266.

Note. I had to use the 12022015 firmware because SSL wouldn't work on previous versions.

Code: Select allpo_token="<TOKEN>"
po_user="<USER>"
po_title="Test"
po_string="token="..po_token.."&user="..po_user.."&message=test&title="..po_title
post_length=string.len(po_string)

conn=net.createConnection(net.TCP, 1)
    conn:on("receive", function(conn, payload)
     print(payload)
    end )
    conn:connect("443","api.pushover.net")
    conn:send("POST /1/messages.json HTTP/1.1\r\nHost: api.pushover.net\r\n"
    .."Connection: keep-alive\r\nkeep-alive: 1\r\nPragma: no-cache\r\n"
    .."Cache-Control: no-cache\r\nContent-Type: application/x-www-form-urlencoded"
    .."\r\nContent-Length: "..post_length.."\r\nAccept: */*\r\n\r\n"
    ..po_string
)
    conn:close()
User avatar
By Feilim Breatnach
#11547 Hi ribs99,

Many thanks for the code snippet and tips on the firmware - just to be sure, is this the firmware you mean:
https://github.com/nodemcu/nodemcu-firm ... 150212.bin

I've managed to fry my 2 ESP-01 modules in the meantime due to a dodgy FTDI module, so when I get some replacements I'll give this a try!

I had tried something else in the meantime where I wrote a PHP based Pushover bridge script and hosted it on a personal web server, I then tried a standard HTTP GET request to this from the ESP module but I still had issues.

As an aside, can I ask what tool you use to upload scripts to the ESP module? I noticed whilst using Luatool that there is a bug when uploading any LUA script which has "\r\n" characters, especially if there is a few chained together such as in your snippet. In this scenario, Luatool seems to fall over on the upload when trying to split the script for line by line write to the module.
User avatar
By ribs99
#11753 That's the correct firmware and the one I'm using at the moment. I'm using the Lua Uploader tool from Hari Wiguna which you can download here: https://github.com/hwiguna/g33k/blob/ma ... .0.2.4.zip

I did exactly the same as you did with the PHP bridge script to start with :D

I'm currently working on a Wi-fi PIR sensor for my home which sends a Pushover message when the alarm is triggered, I'm a PHP coder so trying to get my head around LUA at the moment.