WiFi module as client accessing url

I have the module setup and serving weather data on a webpage. I would like to have the WiFi module act like a client and access a webpage on the internet. Reading though the documents, the only connection that acts like a client is TCP. Can I simply put in a url I want to access in the tcp connection and it will work or do I need to break up the connection in to steps? I need to be able to change the url frequently.

Comments

  • Yes, HTTP is a tcp client and there is code out there to do requests.

    I have a project here that connected to a weather service.

    I also have a weather station on my roof that sends UDP packets to my webserver on my network so I can see weather data on my website here.

    One uses a XBEE unit and the other a ESP8266 module. Both are connected to my WiFi network.

    Mike
  • CapdiamontCapdiamont Posts: 204
    edited 2020-02-02 - 20:54:15
    I'm trying to access a url at weather underground to post data. I got my code to put together a valid URL to post data, which works in a browser. There is three wifi module connection types for the module. HTTP, Websocket and TCP. TCP seems to be the only client type connect and I need a client type connection. It doesn't seem to be connecting.

  • This should be simple enough. An HTTP request is a TCP connect where you make a connection and send one piece of information and get a response back at which point you can close the connection. There are basically two types of requests. HTTP GET, HTTP POST. With GET the request encodes the request in the URI. With POST there is a second packet that contains the request.

    Using the Parallax ESP module you need to do these things.

    send a connect event for the URL:
    send a GET request with your weather keys
    receive the data back from there service
    close the connection

    I see you are using the weather underground. Looking at there site it looks like that service is no longer available. I am using open weather for my data and you can also use AccuWeather as well.

    First send CMD CONNECT "api.openweathermap.org" , 80
    Next send CMD SEND "GET /data/2.5/weather?yourweatherkeyanddata
    Also you need to end that request with " HTTP/1.1" and some other data but should not be necessary.
    You need to end that request with two CR/LF codes to tell the site your finished sending your request.
    Then send CMD RECV handle size to get your data back
    Finally send CMD CLOSE handle

    Mike
  • My url does work in a browser to post to weather underground. This would be my second connection on the WiFi module. 1st is serving a webpage. Terminal is also used and that might be counted as a connection. Is sending http/1.1 needed or optional? The two Cr/of codes, does that mean I have to send two or four characters? I tried experimenting this morning but didn’t get it to work. I will have to think more and learn more.
  • Have you looked at Parallax's "Temperature from OpenWeatherMap" example? It's a C code example on GitHub, within Parallax's "Parallax-Wi-Fi-Apps" example code. It should provide, with some changes to the URL (to use weather underground rather than open weather), a good example of what you are trying to do.

    https://github.com/parallaxinc/Parallax-Wi-Fi-Apps/blob/master/Firmware-Package-Subfolders/Examples/Propeller%20C/Temperature%20from%20OpenWeatherMap.c

    dgately
  • CapdiamontCapdiamont Posts: 204
    edited 2020-02-13 - 00:45:10
    I have not looked at that. Thank you!

    Looking at the code, yes, it is total of four characters.

    If I don't want data back, do I need to scan?
Sign In or Register to comment.