I'm building my first Arduino project. You can see the basics of what I've done, here: http://lostechies.com/derickbailey/2013/04/10/a-first-look-at-my-arduino-bbq-thermometer/ - it's a network enabled BBQ thermometer, to tell me when my meat is done cooking on the grill.
I've got this set up with a basic HTTP server to produce a JSON document when an HTTP request is made. All of the HTTP handing code that I'm using comes from the samples that are built in to the Arduino IDE software.
The Ethernet Shield version of this code seems to work great. It seems to run for as long as I let the thing stay plugged in / turned on. But when I switch over to my Arduino WiFi shield, and upload the WiFi version of my code - which is also based on the samples in the WiFi libraries demos - it stops responding to requests after about 10 minutes or so.
I'm using an Arduino Undo R3, with the latest Arduino WiFi shield. I've got Arduino IDE v1.0 on my Mac. Everything compiles fine, and seems to run fine for a while.
The HTTP server code very quickly starts having problems. If I put up a simple web page with jQuery.ajax calls to hit the http server every 3 seconds, approximately 1 in 3 requests will fail, almost immediately. Once it moves beyond 10+ minutes, the HTTP server code on the Arduino just stops responding entirely.
It's as if I have a resource leak on HTTP clients, and they aren't being cleaned up... but this is a total guess.
For the gist of what I'm doing, see the code found here: https://github.com/arduino/wifishield/tree/master/libraries/WiFi/examples/WifiWebServer
I've literally just copy & pasted this code, turned it on, and then it starts erroring out. I don't even have to modify the code anymore than setting the right SSID and password, and setting a CORS: * header in the HTTP response. Once I upload it to my Arduino, it starts bombing requests frequently, and a few minutes later, it stops responding entirely.
Has anyone seen this problem before, with the WiFi shield? Does anyone have better HTTP request handling code for the Arduino WiFi shield?
I can provide more information, my actual code, or whatever else is needed, as well.
Related
Newbie in the community, here. First of all, thanks for all the help in all these years i've been working on embedded development :D
I have a problem with an Atmel AT91RM9200 ARM microprocessor, connected via RMII to a Mikrel KSZ8863 ethernet physical interface. The ARM is loaded with U-Boot 1.1.2, which loads the Linux Kernel v2.4.27.
I manually added the code to interface U-Boot with the KSZ.
The problem is:
Using U-Boot, if I try to download something from my TFTP server (located in the same network), the connection sometimes has so many timeouts that the download fails, and sometimes has just 2 or 3 timeouts.
I checked the U-Boot FAQ page, and the most probable reason for the timeouts is a wrong speed configuration, which I double checked.
What could be the reason for the unreliability of my connection?
Thanks,
Loranzp.
Setup a minimalist network consistent of TFTP server, client and Sniffer (Wireshark in promiscuous mode) (if you use a switch it must have a repeater port where to connect the sniffer PC)
Next run traffic captures and analyze when and how the timeouts occur.
Consider:
TFTP BlockSize too big leading to mishandled IP fragmentation.
Server provides the packets too fast after REQ or ACK
Not correctly handling block number roll-over (only when handling big files)
etc
I am using java mail 1.6 on Kubuntu Linux 18.04. It all works beautifully. I am connecting to an IMAP server, getting email, etc.
But there is one thing that is causing me grief.
After I close my laptop for a short period of time (so the laptop is probably sleeping), and then open it up, java mail keeps working just fine.
However after I close my laptop for a long period of time (overnight, so the laptop has probably suspended), and then I open it open it up, two things happen:
idle stops working (I have coded this with both IdleManager and
folder.idle, and get the same issue)
when I close a Store or a Folder javamail simpy hangs.
I am guessing that somehow the TCP connection to the IMAP server has died, or maybe I have some timeout set wrong.
I would post code but its buried in a large application, and I am hoping someone has seen this issue before and it has a simple fix.
gym
I'm trying to use AT commands to setup a BGS2-W modem on a custom board to connect to a site over TLS, but the modem is not reacting to my commands and no certificates are being set.
I'm using the command
AT^SBNW
to send the commands as documented in Transport Layer Security for Client
TCP/IP Services doc (https://ptelectronics.ru/wp-content/uploads/organizatsiya_bezopasnogo_ssl-soedineniya.pdf#page=8).
Unfortunately, the document provides no examples, and I haven't been able to find any samples showing the usage of this command online.
The document linked has a java commandline tool attached that will send a cert from a PC, however I am unable to use this tool (I don't have the connection to the modem).
If anyone has any idea's on how to use this command I could very much use the help.
Note: I'm trying to set the certificates from within code running on a PIC18 - this isn't a final incarnation, I just need the certificates loaded so I can connect to our secure server.
Well, guess this one isn't going to find an answer anytime soon :)
So, its fairly easy to capture the output from the javatool - I'm using Com0Com to emulate 2 connected ports, then using termite to manually input on one port while telling the java app to connect to the other.
The first query from the java app expects an "OK" response, I find it easiest to send the response before starting the java app (I guess it gets cached in the recv buffer of the emulated port).
The javatool then sends "AT^SBNW=is_cert,1\r", and you can type in the reply in termite "SECURE CMD READY: SEND COMMAND ..."
After this a large binary dump comes through. You can decode the dump using the structure described in Application Note 62 (https://ptelectronics.ru/wp-content/uploads/organizatsiya_bezopasnogo_ssl-soedineniya.pdf). That should get all the data required to generate the same binary within code.
When I connect my Arduino Mega ADK board to an AOA Android app everything is fine (initially), the connection to the ADK board is fully functional in both directions. However, if the screen rotates, someone hits back, the screen locks, etc, when the app restarts the openAccessory call to the USB manager always returns null. So students have to unplug the USB before the connection can be made again.
I've figured out the problem is related to the Input Stream, because if I don't start the Thread to receive commands then there is no issue. However that's not really a useful fix. :)
My code is here:
https://github.com/ME435/AndroidLibraries_v01/blob/master/src/edu/rosehulman/me435/AccessoryActivity.java
I just subclass my AccessoryActivity in apps like this...
https://github.com/ME435/LED-Toggle/blob/master/src/edu/rosehulman/ledtoggle/LedToggleActivity.java
It's not robust, but it's very simple for students. Thoughts on my issue?
I'm attempting to write my own http 1.1 server, just for fun and learning about more about HTTP, sockets, and threading.
I've gotten a good start i think with only delivering static pages (using c, which I would prefer to stay in for the time being). I have a test page I wrote a while ago and deliver it's ~50 files in 124ms according to chrome, without using threads or keep-alive sockets.
I've found it very difficult to get threading/keep-alive working at all. There are little to no resources on the web (that I can find in my hours of Googling) that explain keep-alive connections in detail. If anyone could recommend a good book on HTTP server programming, I would greatly appreciate it.
I've done some threading and socket programming before by making a simple chat program, so I have at least some experience with it.
The issue I'm having is that when I attempt to incorporate threads, the client browser sets up multiple connections. Somewhere along the line, the server gets confused and the client just sits there waiting for responses and the server stops doing anything. I send the Connection: Keep-Alive header, but that doesn't change anything and when I incorporate keep-alive it and create a loop for getting requests in the threaded function, it stalls until the connection is closed.
I would appreciate it if someone could give me some pseudo code on how to get keep alive/threading working for this so the client stops creating multiple connections at a time.
A brief description of whats going on:
main function
load in static pages to large array of fileinfo struct that hold the file data and length
create the socket
set it to listen to port 80
set it to listen for 10 connections at a time(i know this is low...)
start an endless loop
block while waiting for someone to connect
check if it's a localhost connection
shutdown the server
otherwise
start a thread(with pthread), sending it the socket variable
loop
Thread Function
setsock opt for 3 sec timeout on send/recv and enable Keep-alive
start endless loop
read in request
if request timed out, break the loop
Validate Request function call
Create Reponse function call
Send response
if request contained Connection: close header break the loop
loop
close socket
return
I would recommend looking at GNU libmicrohttpd. It focuses squarely on providing a framework upon which to build HTTP 1.1 servers. It is small and supports keep-alive with and without threading. (Personally I use it without threading. It has several threading models too.)
Even if you decide to write your web server from scratch, I would suggest looking at libmicrohttpd to gain insight in not only how the protocol works, but how the library models "the work flow" of a web server in a very clean way. I think it is a mistake to imagine that keep-alive implies threading and I think it is an impediment to understanding keep-alive.
(Regarding Apaches' credits as a web server, it is pretty huge, and there is a lot in there not related to protocols, but rather things like its plugin system and so on.)
I'd recommend grabbing the source for Apache and seeing how they handle it. There's not much point in psuedo code when you can see how the real thing works.
Perhaps you could look at Apache's code for some clues. It is written in C.
Hopefully someone will come along and give a more detailed answer :)