1:02 pm


Silver
April 11, 2011

I'm working on using an AVR and a Wiznet module to update a Thingspeak channel and seem to be doing something wrong. As a test, I wrote a very simple VB6 program using the same header and format and it works fine.
However, sending the same header and data with my Wiznet module, I get the following response:
<html>
<head>
<title>400 Bad Request</title>
</head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/0.8.53</center>
</body>
</html>
The actual data I'm sending looks like:
field1=80.0&field2=95.0
So, is this response one that you're sending or I am on the wrong track? Any idea why the request is so messed up?
Any help appreciated.
Thanks,
Bob
7:50 pm

Admin
March 14, 2011

Hi, can you show me the full request you're sending (without your api key) so I can take a look at it? Also are you using GET or POST? Since our nginx server is sending you an automatic 400, I don't think your response is even reaching our actual ThingSpeak application.
As a quick test, go to this address in your browser:
http://api.thingspeak.com/update?key=YOUR_WRITE_API_KEY&field1=80.0&field2=95.0
replacing YOUR_WRITE_API_KEY appropriately. It should update your channel.
9:11 pm


Silver
April 11, 2011

Here's my full request:
POST /update HTTP/1.1
Host: api.thingspeak.com
Connection: close
X-THINGSPEAKAPIKEY: ****************
Content-Type: application/x-www-form-urlencoded
Content-Length: 23
field1=80.0&field2=95.0
I'm sending it to 184.106.153.149 and Port 80.
I copied this from the Arduino example on your site.
I also tried the link from your reply and that worked correctly just like my VB6 program.
Any thoughts? Thanks.
Bob
11:33 pm

Admin
January 18, 2011

8:58 am


Silver
April 11, 2011

I guess I didn't explain myself very well. I am not using an Arduino or an ethernet shield. I am using a mega328 and a wiznet wiz810mj module. This is basically the same processor and ethernet chip as the Arduino combination. I am programming with Bascom AVR. I have done several projects with this combination and it has worked very well.
So apparently I am getting to your server but it doesn't like my request - is that correct? Is there any way of finding out more detail or what the server is seeing?
I feel like I'm really close but not quite there yet.
Thanks,
Bob
9:58 am

Admin
March 14, 2011

Can you send a post to this URL:
http://posttestserver.com/post.php
according to the instructions here:
If that works, please provide me with the link to your successful POST and I'll take a look at it.
2:54 pm


Silver
April 11, 2011

I guess I'm not sure how to do that. The wiznet module doesn't do DNS so I don't know how to send my post to another address. I've still got a lot to learn.
The good news is that I'm making progress. I can now post to the channel with my wiznet - the first time - but after that, at least for several hours, I can't connect but, if I change my port say from 5000 to 5001, then I can post again. If I change my port again to 5002 then I can post yet again.
I don't understand why I have to change the port each time. Is there some caching going on somewhere? Why could I connect on a certain port and then not connect a second time a few minutes later but could connect quite a while later?
Anybody able to shed any light on this issue?
Thanks for all the help to date.
Bob
Bob,
We do not have much experience with the WizNet except for on the Arduino Ethernet Shield. All I know if that it locks up a lot. So, I have a watch dog timer that kills the connection and restarts the WizNet chip.
I would check to see that you are closing the connection to the server. The ports 5000 that you are speaking of our local ports. A device makes a connection to the internet and has a source and destination IP and port. Our port is 80 (destination). 5000 ish would be the source port. Like I said, the only thing I can think of is that once you use a source port (socket), you are not closing it so it can be reused for the next connection. Also, check to see if you are using HTTP 1.0 or HTTP 1.1 – HTTP 1.1 allows for keep-alive and you do not have to shut off the port on every connection.
Let us know what you find.
7:19 pm


Silver
April 11, 2011

Thanks for sticking with me on this. I am using HTTP 1.1 and using 80 as the destination port. After a successful channel update, I send a disconnect command to the module and the Wiznet status shows that the connection and socket are closed. But I agree it seems like the connection is not being closed correctly.
When I have a successful connection, here's the reply from your server:
HTTP/1.1 200 OK
Server: nginx/0.8.53
Date: Fri, 15 Apr 2011 19:34:28 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Status: 200
ETag: "1aa48fc4880bb0c9b8a3bf979d3b917e"
Cache-Control: max-age=0, private, must-revalidate
3
803
0
If I send an update at a specific time to my channel, is there any way you can check on your end to see if the connection was properly closed? Other than that, I'm really pushing my knowledge here.
Thanks,
Bob
10:24 pm


Silver
April 11, 2011

So I've done everything I can think to disconnect and close the connection correctly. Unfortunately I still can't re-use the same port. Although your server sends back a "Connection: close", it just doesn't look like it's being closed.
I do have a hack running that increments the port each post and then wraps around after a day or two. The results can be seen here:
http://gardnerswebsite.com/thingspeak.html
I'll keep working on it. Please let me know if you have any ideas.
Thanks,
Bob
12:05 am

Admin
January 18, 2011

1:52 pm


Silver
April 11, 2011

So I finally got everything working correctly. The port problem appeared to be caused by an ARP cache used by my ISP. I have posted more information about the problem and the project on my site:
http://gardnerswebsite.com/thingspeak/index.html
I will post the Bascom source code in the next couple of days after I clean it up a little and add more documentation.Thanks for your help.
Bob
Most Users Ever Online: 166
Currently Online:
29 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
Advantagetreeexperts, laundrydaddyuk, techhhelp5, ken, tran, huldacormierModerators: cstapels: 460
Administrators: Hans: 405, lee: 457