Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

Http.post()

Hi, i need to send a POST message to server from ESP8266 client . i've tried GET message with 'Http.get' cmd, in the old README (until the first version of the firmware) was explained the simply Http.get , but i don't find anything about POST.
Could someone help me?
thanks a lot, Andrea
«1

Comments

  • lsmlsm Dublin, Ireland
    edited December 2015
    Hi Andrea! Yes you can use POST:
    Http.request({
    hostname: 'httpbin.org',
    path: '/post'
    }, function(r) { print(r); }).end('This is your POST data');
    That HTTP client functionality is available in the newer firmware, which you can download from https://github.com/cesanta/smart.js#documentation-and-downloads (look for the development firmware builds).
  • Thank you, i'm still using the "old" alpha-2.1. I think is the same, now i try. I have try the latest , but i think that sometimes flashnchips don't do the flash correctly. i try to explain: i had flash the firmware a lot of time on a lot of esp, i've tried all the version, i've used flashnchips and sometimes esptool(python).
    Last night i've compile the latest and flash with flashnchips. Everytime i try to send a get msg monitor answer me "Trap 28 ......". I'have flash other 4 files in the platforms/esp8266/fs and after make.sh i've find 17% of memory.
    Maybe less memory can give problem? or maybe a lot of upload? Now i downgrade to 2.1 and delete some file that i don't need and return me 23% of memory, like a 'normal flash' without adding files, and i have no problem.
    i have think also that the winbond flash memory don't support a lot of read/write.
    Now i don't have any problem like that. What do you think? What's the meaning of Trap xx?
  • adminadmin Dublin, Ireland
    I am getting a little confused.
    apmascalabs, could you clarify what firmware you're using please?

  • Sorry, now alpha 2.1
  • adminadmin Dublin, Ireland
    Alpha 2.1 firmware cannot do POST.
    Only the latest firmware can. Please use this FW:

    https://backend.cesanta.com/devel/smartjs_devel_win.zip  (windows)
    https://backend.cesanta.com/devel/smartjs_devel_mac.zip  (mac)
  • Thank  you, I have the latest source code, I'm on linux. sorry for my bad explanation.
    Now I still use alpha-2.1 and i will flash the latest again.
     
  • adminadmin Dublin, Ireland
    Sure, please let us know how the current build works.
  • Halo, have you implemented with other qt libraries the beta release? I've got dome problem compile the latest. Return me that don't find QNetworkAccessManager

  • adminadmin Dublin, Ireland

    What QT library are you using, and what OS?

  • Qt5 debian jessie

  • adminadmin Dublin, Ireland
    edited December 2015

    Make sure qt5-network module is installed.

  • Hi, Merry Christmas!!
    Qt5-network is installed, now i've got problem with QDebug... Probably it's always a problem of qt... but this i don't know how to resolve!

  • adminadmin Dublin, Ireland

    Merry Christmas!
    QT build problems is something we do not handle - please refer to the appropriate QT support!

  • Yes, i know... Thanks!!

  • Hi, after a lot of problem(I will open another discussion soon..) I have Beta release running so I can try to send a POST.I've tried the example of site (http.client) and I receive answer from server.
    Now I'm trying this one:
    var post_options = {
                        "hostname":"localhost",
                        "port":7474,
                        "path":"/db/data/cypher",
                        "method":"POST",
                        "headers":{"Content-Type":"application/json",
                                   "Content-Length":78,
                                   "Authorization":"Basic bmVvNGo6bmVvNGo="}
                        };

    var post_data = {"query":"CREATE (n:Node { name : {name} }) RETURN n","params":{"this":"one"}};

    client_obj = Http.request(post_options, function(cb){console.log(cb);});

    client_obj.write(post_data);
    client_obj.end();

    but don't let me access to the db (with the right Authorization).
    Is this the correct method to post data?
    Are maybe some limitations on headers?
    Seems that headers don't pass.
    I've also tried to put the query in the endpoint but nothing change.
    thank you
  • adminadmin Dublin, Ireland
    Thanks Andrea!

    The reason is that we did not respect headers option, and thus headers were not forwarded to the server.
    That just has been fixed, you can download latest firmware from:

    URL: https://backend.cesanta.com/devel/win_fw_20160104_215306.zip

    URL: https://backend.cesanta.com/devel/mac_fw_20160104_215306.zip


    (links are for windows and mac respectively)

    Alternatively, you can build from sources yourself.

    Let us know how it works for you.


  • Hi, I've downloaded the win firmware (https://backend.cesanta.com/devel/win_fw_20160104_215306.zip) and  I've tried to flash, but answer me that ' failed to flash at 0xec000'.I see in the 'firmware/ESP8266/Smart.js' folder the '0xec000.bin' file  . 
    In other previous version of Beta release I had find the '0xec000.bin' and everytime I try to flash with this bin present I have difficult to flash ( Flashnchips answer me 'failed to flash at 0xec000' and esptool give me 'invalid head of packet' or ' Writing at 0x000f4000... (51 %)
    A fatal error occurred: Failed to write to target Flash after seq 32 (got result 0x1, 0x7)').
    Sometimes the flash go until the 'Leaving' in esptool or give me 'flash successfully' in flashnchips, but when I remove GPIO0 from GND I receive only garbage.

    In the  https://backend.cesanta.com/devel/smartjs_devel_win.zip  (windows) linked at the top of this discussion , the last .bin file is 0x73000.bin and the flash go ok with Flashnchips and also with esptool.
     In another one of the previous window Beta version I find 0x70000.bin and the flash go ok.
    It's maybe a problem of the download?
    I've tried to re-download but nothing change.
    I've download also the sources and compiled with debian , return me the 'firmware' folder with inside the '0x00000.bin 0x11000.bin 0xec000.bin'. Also this ,give me error when flash or if flash end right, when reboot return only garbage.


  • If you prefer I move this comment in another discussion
  • SergeySergey Dublin, Ireland
    Just to clarify,
    1. What device are you using, with what flash size
    2. Are you able to flash other firmwares successfuly?
  • Hello Sergey, 
    I'm using ESP8266-01 512k .
    I've got another one with 4M but I don't have tried to flash the last on it.
    with the 512k I'm able to flash with esptool Smart.js alpha-2.1, nodeMCU, the original fw with AT conmands and all your version that don't have 0xec000.bin file.
    Also the fw with 0xec sometimes flash ok , but I can't comunicate, the blu led flash continuosly, and monitor return me infinity garbage.
  • adminadmin Dublin, Ireland
    Newest firmware takes more than 512k, so ESP-01 won't work with it.
    Could you try it on nodemcu module please?
  • No, I haven't. This evening I will try to flash the module with 4M. 
    You think the problem is only the flash size? 
  • adminadmin Dublin, Ireland
    I think so, since I can flash and use my nodemcu module with no problem.
  • Ok, thank you, I will keep you updated.
  • Hi, now I'm trying to flash a ESP12 (not 12E) with the firmware 'https://backend.cesanta.com/devel/win_fw_20160104_215306.zip' . At the first flash I receive :

    --- flashed successfully

    --- connected rp�n�����#�n��{nr���;���lxrp�n����p��nn���r��#�n�$�l`�8`rn|��n�����`9~����#�n�$���nn���l`nn������don't use rtc mem data
    --- disconnected
    --- connected: tail 4 chksum 0x7a load 0x3ffe8000, len 2480, room 4 tail 12 chksum 0xda ho 0 tail 12 room 4 load 0x3ffe89b0, len 2004, room 12 tail 8 chksum 0x40 csum 0x40 don't use rtc mem data Fatal exception 9(LoadStoreAlignmentCause): epc1=0x40257e2c, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0000001d, depc=0x00000000 ets Jan 8 2013,rst cause:2, boot mode:(3,7)
    load 0x40100000, len 29828, room 16 tail 4 chksum 0x7a load 0x3ffe8000, len 2480, room 4 tail 12 chksum 0xda ho 0 tail 12 room 4 load 0x3ffe89b0, len 2004, room 12 tail 8 chksum 0x40 csum 0x40 don't use rtc mem data Fatal exception 0(IllegalInstructionCause): epc1=0x40257e22, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0000001d, depc=0x00000000

    If I try to connect nothing happen.

    If I try to re-flash is the same(most time the flash fail).

    the flash is:

    $ python esptool.py -b 115200 --p /dev/ttyUSB0 flash_id
    Connecting...
    Manufacturer: ef
    Device: 4016

    So I understand that is a 32Mb(4MB) flash of Winbond(true?).

    Flash under Debian with esptool I receive:

    $ python esptool.py -b 115200 --p /dev/ttyUSB0 write_flash 0x00000 0x00000.bin 0x11000 0x11000.bin 0xec000 0xec000.bin
    Connecting...
    Erasing flash...
    Wrote 34816 bytes at 0x00000000 in 3.4 seconds (82.6 kbit/s)...
    Erasing flash...
    Wrote 402432 bytes at 0x00011000 in 39.0 seconds (82.6 kbit/s)...
    Erasing flash...
    Writing at 0x000f1c00... (37 %)
    A fatal error occurred: Invalid head of packet


    other times i receive:
    Writing at 0x000ec400... (3 %)
    A fatal error occurred: Failed to write to target Flash after seq 1 (got result 0x1, 0x7)
    with the .bin compiled from source and also with the .bin from win version.
    The same things with a 512k, 1MB and 4MB.
    Now I'm waiting a nodeMCU board, but I don't understand why until the precedent version ( with some strange issue that I described) I can flash and now no.
    I have also tried to flash one file at time, no problem with 0x00000.bin and 0x11000.bin, when I flash the 0xec000.bin sometimes the flash go ok but when I connect I don't find any file with 'File.list('*')' .
    I don't understand if esptool erase only the given address.
    No problem with a version with 0x70000.bin and 0x73000.bin and 'alpha-2.1' with 0x6d000.bin.
    I repeat: every time I try to flash a version with 0xec000.bin file I got a problem.
    I've downloaded also the last esptool but nothing change.
    I've tried to re-download Smart.js from your link, from GitHub and from the Release page but nothing.
    Please, try to help me (if possible) because I really don't understand what is going wrong.
    Thanks





  • rojerrojer Dublin, Ireland

    the flash is:

    $ python esptool.py -b 115200 --p /dev/ttyUSB0 flash_id
    Connecting...
    Manufacturer: ef
    Device: 4016

    So I understand that is a 32Mb(4MB) flash of Winbond(true?).

    Flash under Debian with esptool I receive:

    $ python esptool.py -b 115200 --p /dev/ttyUSB0 write_flash 0x00000 0x00000.bin 0x11000 0x11000.bin 0xec000 0xec000.bin
    Connecting...
    Erasing flash...
    Wrote 34816 bytes at 0x00000000 in 3.4 seconds (82.6 kbit/s)...
    Erasing flash...
    Wrote 402432 bytes at 0x00011000 in 39.0 seconds (82.6 kbit/s)...
    Erasing flash...
    Writing at 0x000f1c00... (37 %)
    A fatal error occurred: Invalid head of packet


    other times i receive:
    Writing at 0x000ec400... (3 %)
    A fatal error occurred: Failed to write to target Flash after seq 1 (got result 0x1, 0x7)
    with the .bin compiled from source and also with the .bin from win version.
    The same things with a 512k, 1MB and 4MB.
    Now I'm waiting a nodeMCU board, but I don't understand why until the precedent version ( with some strange issue that I described) I can flash and now no.
    I have also tried to flash one file at time, no problem with 0x00000.bin and 0x11000.bin, when I flash the 0xec000.bin sometimes the flash go ok but when I connect I don't find any file with 'File.list('*')' .
    I don't understand if esptool erase only the given address.
    No problem with a version with 0x70000.bin and 0x73000.bin and 'alpha-2.1' with 0x6d000.bin.
    I repeat: every time I try to flash a version with 0xec000.bin file I got a problem.
    I've downloaded also the last esptool but nothing change.
    I've tried to re-download Smart.js from your link, from GitHub and from the Release page but nothing.
    Please, try to help me (if possible) because I really don't understand what is going wrong.
    Thanks

    i think this may be incorrect setting of flash params. your flash chip is indeer 32Mb/4MB, but unless flash params are set correctly, esp won't know it.
    two things to try here:
    first - new flash'n'chips. we've recently made major changes to flashing code, among them auto-detecting flash size and setting params automatically. please try this binary: https://backend.cesanta.com/tmp/flashnchips-20160113.exe (windows)

    if that doesn't work for you (please let me know what happened), second - set flash size and speed manually. please run flash'n'chips with with the following flag: --esp8266-flash-params=dio,32m,40m
    you can also try esptool with --flash_size=32m --flash_mode=dio --flash_freq=40m

  • Hi, thank you for your answer and sorry for the late of my answer.
    Now I've got nodeMCU board with a firmware '20160116-152134', flashed under Linux with esptool and this parameters :' --flash_size=32m --flash_mode=dio --flash_freq=40m' .
    I don't uderstand the meaning of 

    set_errno spiffs error: -10002

    that I read after boot or reboot.

    I'm trying to POST with the same script that I've described in this tread, but this time give me a problem to send the host and all the other parameters.Sometimes return me '[[Circular]]'  sometimes ' 404' , and sometimes '{"body":"","url":"","method":"","headers":{"Server":"Jetty(9.2.4.v20141103)","Connection":"close","Content-Length":"0"}}' ,so I understand that nothing pass.

    I'm connected, if I send GET I have no problem, if I send the simple post to httpbin.org (without body and headers) return me the correct page , but I can't send post to neo4j.

    Before this version, with the link gived me from admin(https://backend.cesanta.com/devel/smartjs_devel_win.zip  (windows)) I receive error to pass the auth.

    After that I've tryied the 20160104 but nothing change.

    Any suggestion?

    If the correct syntax is :

    Http.request({
    hostname: 'httpbin.org',
    path: '/post'
    }, function(r) { print(r); }).end('This is your POST data');
    like Ism say, I have to put body in the endpoint?
    thanks





  • Hi, I've resolved the POST request, now I'm able to send.
     I looking for the meaning of

    set_errno spiffs error:-10002
  • SergeySergey Dublin, Ireland
    That means filesystem error, "file not found".

    https://github.com/pellepl/spiffs/blob/master/src/spiffs.h
  • Ok, but which file? I find that on boot after the AP message .
Sign In or Register to comment.