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

User avatar
By zooto68
#10872 I am trying to get some data from the Wunderground weather API.

To get a response back you simply send a request such as:

http://api.wunderground.com/api/yourAPI ... cisco.json

and you get as json page in return.

My code is:

Code: Select allconn=net.createConnection(net.TCP, 0)

conn:on("connection",function(conn, payload)
            conn:send("GET /api/yourAPIkeyGoesHere/conditions/q/CA/San_Francisco.json\r\n\r\n")
            end)
           
conn:on("receive", function(conn, payload)
    print(payload)
    conn:close()
    end)
t = tmr.now()   
conn:connect(80,'api.wunderground.com')


and yet all I get back is:

> HTTP/1.0 400 Bad Request
Server: AkamaiGHost
Mime-Version: 1.0
Content-Type: text/html
Content-Length: 216
Expires: Fri, 27 Feb 2015 13:14:34 GMT
Date: Fri, 27 Feb 2015 13:14:34 GMT
Connection: close

<HTML><HEAD>
<TITLE>Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
Your browser sent a request that this server could not understand.<P>
Reference&#32;&#35;7&#46;1d4e7b5c&#46;1425042874&#46;0
</BODY>
</HTML>

What am I doing wrong please?

Thanks,

Mike
User avatar
By zooto68
#10874 OK I've worked it out. My HTTP header needed more info. it should have been..

Code: Select allconn:send("GET /api/YourAPIKey/conditions/q/CA/San_Francisco.json"
                        .." HTTP/1.1\r\n"
                        .."Host: api.wunderground.com\r\n"
                        .."Connection: close\r\n"
                        .."Accept: */*\r\n"
                        .."User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; )\r\n"
                        .."\r\n"
                        )
User avatar
By zooto68
#10879 The returned characters seem to be 1431. The latest firmware is supposed to have increased the buffer size from 1024 to 4096 so shouldn't I be receiving the entire json response?

A full response seems to be approx 2691 characters which should easily fit in the 4096 sized buffer.

Any ideas please?

Mike