The Arduino WiFi Shield

download The Arduino WiFi Shield

of 55

Embed Size (px)

description

The nitty-gritty of how the Arduino WiFi shield goes wrong any time a network connection is dropped

Transcript of The Arduino WiFi Shield

  • The Arduino WiFi Shield Katrina Ellison Geltman March 27, 2014
  • Arduino UNO R3 Arduino WiFi Shield
  • Arduino UNO R3 Arduino WiFi Shield
  • + vs.
  • + vs.
  • How it Works
  • Getting set up
  • In the beginning, you have: WiFi ShieldComputer WiFi Router Arduino
  • You set up the basics. WiFi ShieldComputer WiFi Router Arduino WiFi driver Server object
  • You request to connect to the network. WiFi ShieldComputer WiFi Router Arduino WiFi driver Request to connect Server object
  • If youre lucky, you connect successfully. WiFi ShieldComputer WiFi Router Arduino WiFi driverConnection successful Request to connect Server object
  • You start your server. WiFi ShieldComputer WiFi Router Arduino Server object Start TCP server listening on socket/port
  • Now its listening on a particular port. WiFi ShieldComputer WiFi Router Arduino Server object
  • Youre ready to go!
  • Receiving requests
  • After setup, everything happens in an event loop. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop
  • At the beginning of the loop, a client object is created using the servers port & socket. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop Client object
  • The client asks the WiFi shield whether its active or not. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop Client object What's my state?
  • If there havent been any requests, the client stays inactive. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop Client object Inactive The event loop ends and re-starts.
  • If there havent been any requests, the client stays inactive. ! ! The event loop ends and re-starts. ! I think the client is deleted, but Im not sure how. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop
  • If a request has been made, the client activates. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop Client object Client object Connected! Request!
  • Your code asks the client object for whatever data its receiving from your computer. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop Client object Client object Connected! Request! Data?
  • If there is data, it reads it and processes it. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop Client object Client object Read data Request! Read data
  • (This is when your Arduino actually does something) WiFi ShieldComputer WiFi Router Arduino Server object Your code loop Client object Client object Read data Request! Read data
  • Then the event loop ends and the client is deleted. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop
  • ! Then the event loop ends and the client is deleted. (I think) WiFi ShieldComputer WiFi Router Arduino Server object Your code loop Client object Inactive
  • Thats all good
  • How it goes wrong
  • Bad things happen if you disconnect from the network. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop
  • The server doesnt reconnect properly when the network reconnects. WiFi ShieldComputer WiFi Router Arduino Server object Your code loop
  • We know this from our debugging output. Socket Port Server Status Client Status -1 0 0 0
  • We know this from our debugging output. Socket Port Server Status Client Status -1 0 0 0 0 80 0 0
  • We know this from our debugging output. Socket Port Server Status Client Status -1 0 0 0 0 80 0 0 Still active!
  • We know this from our debugging output. Socket Port Server Status Client Status -1 0 0 0 0 80 0 0 No server!
  • How to x it
  • Manually release port & socket
  • void WiFiServer::disconnect() { WiFiClass::_state[_sock] = -1; WiFiClass::_server_port[_sock] = 0; }
  • void WiFiServer::disconnect() { WiFiClass::_state[_sock] = -1; WiFiClass::_server_port[_sock] = 0; }
  • void WiFiServer::disconnect() { WiFiClass::_state[_sock] = -1; WiFiClass::_server_port[_sock] = 0; }
  • void WiFiServer::disconnect() { WiFiClass::_state[_sock] = -1; WiFiClass::_server_port[_sock] = 0; }
  • Socket Port Server Status Client Status -1 0 0 0
  • Socket Port Server Status Client Status -1 0 0 0 0 80 1 0
  • It works!
  • It works! trivially
  • It doesnt work if a client object has ever been created
  • It doesnt work if a client object has ever been created This makes it useless!
  • It doesnt work if a client object has ever been created usually This makes it useless!
  • Memory management?
  • But available memory does not change from loop to loop.
  • I dont really know C++
  • Or network programming
  • So I would love to hear your ideas
  • But whether or not you can help
  • Your main takeaway should be
  • Arduino UNO R3 Arduino WiFi Shield