the arduino wifi shield

55
The Arduino WiFi Shield Katrina Ellison Geltman March 27, 2014

Upload: kellison00

Post on 21-Apr-2017

2.805 views

Category:

Devices & Hardware


1 download

TRANSCRIPT

Page 1: The Arduino WiFi Shield

The Arduino WiFi Shield

Katrina Ellison Geltman March 27, 2014

Page 2: The Arduino WiFi Shield

Arduino UNO R3 Arduino WiFi Shield

Page 3: The Arduino WiFi Shield

Arduino UNO R3 Arduino WiFi Shield

Page 4: The Arduino WiFi Shield

+

vs.

Page 5: The Arduino WiFi Shield

+

vs.

Page 6: The Arduino WiFi Shield

How it Works

Page 7: The Arduino WiFi Shield

Getting set up

Page 8: The Arduino WiFi Shield

In the beginning, you have:

WiFi ShieldComputer WiFi RouterArduino

Page 9: The Arduino WiFi Shield

You set up the basics.

WiFi ShieldComputer WiFi RouterArduino

WiFi driver

Serverobject

Page 10: The Arduino WiFi Shield

You request to connect to the network.

WiFi ShieldComputer WiFi RouterArduino

WiFi driver

Request to connectServerobject

Page 11: The Arduino WiFi Shield

If you’re lucky, you connect successfully.

WiFi ShieldComputer WiFi RouterArduino

WiFi driverConnection successful

Request to connectServerobject

Page 12: The Arduino WiFi Shield

You start your server.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Start TCP server listening onsocket/port

Page 13: The Arduino WiFi Shield

Now it’s listening on a particular port.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Page 14: The Arduino WiFi Shield

You’re ready to go!

Page 15: The Arduino WiFi Shield

Receiving requests

Page 16: The Arduino WiFi Shield

After setup, everything happens in an event loop.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

Page 17: The Arduino WiFi Shield

At the beginning of the loop, a client object is created using the server’s port & socket.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

Clientobject

Page 18: The Arduino WiFi Shield

The client asks the WiFi shield whether it’s active or not.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

ClientobjectWhat's my state?

Page 19: The Arduino WiFi Shield

If there haven’t been any requests, the client stays inactive.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

ClientobjectInactive

The event loop ends and re-starts.

Page 20: The Arduino WiFi Shield

If there haven’t been any requests, the client stays inactive.

!!

The event loop ends and re-starts. !

I think the client is deleted, but I’m not sure how.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

Page 21: The Arduino WiFi Shield

If a request has been made, the client activates.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

ClientobjectClientobjectConnected!

Request!

Page 22: The Arduino WiFi Shield

Your code asks the client object for whatever data it’s receiving from your computer.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

ClientobjectClientobjectConnected!

Request!

Data?

Page 23: The Arduino WiFi Shield

If there is data, it reads it and processes it.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

ClientobjectClientobjectRead data

Request!

Read data

Page 24: The Arduino WiFi Shield

(This is when your Arduino actually does something)

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

ClientobjectClientobjectRead data

Request!

Read data

Page 25: The Arduino WiFi Shield

Then the event loop ends and the client is deleted.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

Page 26: The Arduino WiFi Shield

!Then the event loop ends and the client is deleted.

(I think)

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

ClientobjectInactive

Page 27: The Arduino WiFi Shield

That’s all good

Page 28: The Arduino WiFi Shield

How it goes wrong

Page 29: The Arduino WiFi Shield

Bad things happen if you disconnect from the network.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

Page 30: The Arduino WiFi Shield

The server doesn’t reconnect properly when the network reconnects.

WiFi ShieldComputer WiFi RouterArduino

Serverobject

Your code loop

Page 31: The Arduino WiFi Shield

We know this from our debugging output.

Socket Port Server Status

Client Status

-1 0 0 0

Page 32: The Arduino WiFi Shield

We know this from our debugging output.

Socket Port Server Status

Client Status

-1 0 0 0

0 80 0 0

Page 33: The Arduino WiFi Shield

We know this from our debugging output.

Socket Port Server Status

Client Status

-1 0 0 0

0 80 0 0Still active!

Page 34: The Arduino WiFi Shield

We know this from our debugging output.

Socket Port Server Status

Client Status

-1 0 0 0

0 80 0 0

No server!

Page 35: The Arduino WiFi Shield

How to fix it

Page 36: The Arduino WiFi Shield

Manually release port & socket

Page 37: The Arduino WiFi Shield

void WiFiServer::disconnect() { WiFiClass::_state[_sock] = -1; WiFiClass::_server_port[_sock] = 0; }

Page 38: The Arduino WiFi Shield

void WiFiServer::disconnect() { WiFiClass::_state[_sock] = -1; WiFiClass::_server_port[_sock] = 0; }

Page 39: The Arduino WiFi Shield

void WiFiServer::disconnect() { WiFiClass::_state[_sock] = -1; WiFiClass::_server_port[_sock] = 0; }

Page 40: The Arduino WiFi Shield

void WiFiServer::disconnect() { WiFiClass::_state[_sock] = -1; WiFiClass::_server_port[_sock] = 0; }

Page 41: The Arduino WiFi Shield

Socket Port Server Status

Client Status

-1 0 0 0

Page 42: The Arduino WiFi Shield

Socket Port Server Status

Client Status

-1 0 0 0

0 80 1 0

Page 43: The Arduino WiFi Shield

It works!

Page 44: The Arduino WiFi Shield

It works!

… trivially

Page 45: The Arduino WiFi Shield

It doesn’t work if a client object has ever

been created

Page 46: The Arduino WiFi Shield

It doesn’t work if a client object has ever

been created

This makes it useless!

Page 47: The Arduino WiFi Shield

It doesn’t work if a client object has ever

been created

usually

This makes it useless!

Page 48: The Arduino WiFi Shield

Memory management?

Page 49: The Arduino WiFi Shield

But available memory does not change from

loop to loop.

Page 50: The Arduino WiFi Shield

I don’t really know C++

Page 51: The Arduino WiFi Shield

Or network programming

Page 52: The Arduino WiFi Shield

So I would love to hear your ideas

Page 53: The Arduino WiFi Shield

But whether or not you can help

Page 54: The Arduino WiFi Shield

Your main takeaway should be

Page 55: The Arduino WiFi Shield

Arduino UNO R3 Arduino WiFi Shield