HTTP Requests



  • Update:

    After installing the new Ubuntu for Windows 10 and using that to build I got a lot further: I can now connect to the WiFi network without error. Both with your code and with my own.

    I guess the Windows version of the Mono framework has some issues.

    It stalls when fetching the request, but I guess that's because the server is down because I can't connect to it with a browser either.

    arting fake IRQ timer!
    Mono initialized
    
    display full paint time: 41670
    Wake from reset...
    HOST_INTF_REG_OUT: 0xab15
    mgmt frame assign
    SPI initialized
    Initializing Network...
    Connecting to Network...
    resp frame cmd id: 0x10
    resp frame cmd id: 0x11
    resp frame cmd id: 0x12
    resp frame cmd id: 0x13
    Scan found 2 APs:
     * Charlotte, rssi: 73
     * HomeBox-B390_2.4G, rssi: 77
    resp frame cmd id: 0x14
    Joined Wifi Network!
    resp frame cmd id: 0x41
    Network Ready!
    Network ready...
    init dns: mono.phenocode.com
    Beginning HTTP request
    resp frame cmd id: 0x44
    resp frame cmd id: 0x51
    Error response for command: 0x51. Error code: 0xbb38
    failed to handle incoming response for resp queue head
    

    Edit:

    It doesn't work much better with google.com:

    Network Ready!
    init dns: google.com
    resp frame cmd id: 0x44
    resp frame cmd id: 0x51
    resp frame cmd id: 0x51
    Error response for command: 0x51. Error code: 0xbbed
    failed to handle incoming response for resp queue head
    


  • I actually noticed the same, I am not able to get this to work on Windows so I switched over to Mac as my primary development environment.



  • I'd stopped this server without realizing that it was also hosting this example. I have put it back online until I can move it to a more appropriately provisioned (smaller) server.



  • Thank you, now your example works perfectly.

    I guess google.com doesn't work because it expects https.

    I can see in redpine_command_frames.cpp that it also doesn't support other ports than port 80, which is why it didn't work for me.

    @stoffera, do you think you could you add support for other ports? Either as a parameter in the HTTPClient constructor or a function (like client.setPort(5000);) or you could just parse it from from the URL (like you do with the domain or ip). E.g: http://192.168.0.200:5000/media

    Regards,
    Emil



  • Hi @drew & @emil-melgaard great work! I am excited about you guys coding for the wifi module :-)

    First, let me tell you about the error messages you pasted in your posts:

    Error response for command: 0x51. Error code: 0xbbed
    

    The 0x51 command is a HTTP Request command sent from the CPU to the Redpine module. And the module returns an error code: 0xbbed. You need to look at Redpine's Programming Reference Manual to make sense of these. The description of the error code 0xbbed is Invalid packet length, content length and received data length is mismatching. I cannot make sense of this in relation to downloading google.com. But, it could be related to downloading a HTTPS site.

    However, error 0xbb38 is a quirk in redpine's module - it just happens sometimes. The description is Trying to connect non-existenting TCP server socket. But there must be a bug in redpine's firmware, since you can just redo the request and it works fine.

    I have also recently discovered the issue with port numbers. I admit the the current HTTP Client class (and associated command frames) are quick and dirty. So port 80 is hard coded, unfortunately. I will see if I can add the port as a parameter in the command frames first, then look at the http client class.

    If you wish to get a hold of the Redpine Programming reference manual, then drop me your email address in a PM, and I will relay your request to Redpine. (They do not publicly release their documentation :-/ )



  • @emil.melgaard said in HTTP Requests:

    After installing the new Ubuntu for Windows 10 and using that to build I got a lot further: I can now connect to the WiFi network without error.

    I am curious, what is the issue on Windows 10 - that does not exist on their Ubuntu user land? The serial port?



  • @stoffera said in HTTP Requests:

    I have also recently discovered the issue with port numbers. I admit the the current HTTP Client class (and associated command frames) are quick and dirty. So port 80 is hard coded, unfortunately. I will see if I can add the port as a parameter in the command frames first, then look at the http client class.

    It would be perfectly fine for me to have it in the command frames. The http client is simple enough that I can make do without it.

    @stoffera said in HTTP Requests:

    If you wish to get a hold of the Redpine Programming reference manual, then drop me your email address in a PM, and I will relay your request to Redpine. (They do not publicly release their documentation :-/ )

    I have sent you a PM. I don't know if I will go as far as to use the redpine module directly in my code, but I would like to see what it can do and what the errors mean.

    @stoffera said in HTTP Requests:

    I am curious, what is the issue on Windows 10 - that does not exist on their Ubuntu user land? The serial port?

    No, it must be an issue in either the Mono Framework or the compile chain. I always program my Mono from Windows, but the exact same code produce different results depending on where I generate the elf-file. Compiled on Windows it results in the errors on the Mono with the flashing screen and beeps, but compiled on Ubuntu (for Windows) it works perfectly fine.



  • @emil.melgaard , I have added code for HTTPClient support of other TCP/IP ports! But you need to build the library yourself - to take advantage of the features.

    With the new feature you can just do:

    mono::network::HttpClient client("http://192.168.1.5:8080/api/state?on=true");
    

    I added a build guide to the Github README file: https://github.com/getopenmono/mono_framework#building

    from Windows, but the exact same code produce different results depending on where I generate the elf-file.

    Strange! Can you check if you have the same SDK version on both Windows and Ubuntu (version 1.1)? (try monomake version)



  • @stoffera, thank you, that was exactly what I needed. Now everything is working for me.

    The version is (and was) 1.1 on both Windows and Ubuntu, but with the rebuilt library it works fine on Windows for me now (I built the library on Ubuntu and copied it to Windows).

    Thank you again for your help.

    I look forward to your tutorial on power management which is what I think I need the most now. I can't figure out how to turn off the display which is of course really hard on the battery life.



  • @emil.melgaard said in HTTP Requests:

    I look forward to your tutorial on power management which is what I think I need the most now. I can't figure out how to turn off the display which is of course really hard on the battery life.

    Glad to hear that. While waiting for the tutorial, you can control the display LED brightness by:

    IApplicationContext::Instance->DisplayController->setBrightness(255);
    

    For further info see: http://developer.openmono.com/en/latest/reference/mono_display_IDisplayController.html#_CPPv2N4mono7display18IDisplayController13setBrightnessE7uint8_t

    Even if you set the brightness to 0, the display controller chip is still on.

    Advanced power management

    You can also turn off the auxiliary power by cutting (the 3V3 power line):

    IApplicationContext::Instance->PowerManager->PowerSystem->setPowerFence(true);
    

    If you set power fence to true the Wifi module, SD Card and display will loose power. When you re-establish the power, the display/wifi and sd card chip will need to be initialized again - see the init() method.


Log in to reply