Wifi and Android

Hi guys !

I am totally new to arduino that's why I come here to ask for some help. I'm a student and right I've started a project for a company : they want to put some sensors on a table, link the sensors with an arduino board and transfer data on a android device.

I would like to use the WifiShield since I don't want something complicated, with most like an Arduino ADK (to support Android). So first what do you think of this ? I read some posts which recommend an Ethernet shield and then a small router, but as I said I want something simple, moreover the price is not an issue since I don't pay for this things.

Secondly I'm looking for some tutorials to make this wifi connexion, I have this books : Arduino + Android Projects for the Evil Genius & Beginning Android ADK with Arduino
But I'm surprised none of them talk about the wifi connexion (even if they say they do). I googled it all the afternoon but no results :frowning:
I hope you could help me, thank you !!

I initially attempted to make my own project work with a Liksprite CuHead, which is a Clone of the Asynclabs WiShield. I got it to work to some degree nut could not progress beyond a certain point, e.g using certain libraries with the CuHead.
Then I tried a Diysandbox.com Hydrogen. Nice and capable product, but in the end I came across the same problem. If you do go the WiFi shield route I'd recommend this one. I have no experience with the Arduino Wifi Shield, which I believe is certainly a very capable piece of hardware nut it will take some time until libraries for it are fully developed and debugged so the maturity of approaches that of the Ethernet Shield.

I finally decided to try using a little WiFi router ( TP-Link WR703n) connected to the Ethernet card and I can assure you that this is dead simple!

The reason is that the WiFi connection is transparent for the Arduino, so you can take advantage of the Full functionality of the Ethernet library and many other libraries that depend on the Ethernet library like DHCP/Bonjour or ArdOSC.

Further more , if someone else less technically inclined wants to reconfigure the network then they can simply reconfigure the little router through its Web interface. No need to hack around in Arduino code, no compilation and upload.

Hum ok. Well if you say it's really simple I may think about it then ! Do you have any tutorial I could watch to learn a bit more about this and see if I can use it with Android ?

Thanks for your help !

It would help if you could provide some more information as to what software on the Android device is going to receive the data. Is it an application that already exists or areyou going to write/code one ?

From there we can determine in what format and with what protocol to send data.
What sensors are you going to connect, and how are you goin to connect the sensors to the analod inputs, digital inputs or through I2C etc.

It will be some piezoelectric sensors (4 I guess) linked to the arduino board and then I must send data to my phone. I don't have more information about the sensors ; and the android app will be written by myself.

The way with static ip and socket seem to be the easier, not the best one but this could be sufficient.

From my admittedly brief reading about the Android ADK it seems more aimed at connecting Android accessories per USB. If you want to connect an Arduino to an Android device per WiFi you should not need the ADK.
After all you can just collect your data and then send it per UDP. How you format your data is completely up to you as you are going to be the one coding the receiving software the world is open to you, so to speak ;-). You could of course use an already existing protocol that perhaps is based on UDP and would allow you to focus on the core of your application and not on coding a protocol. I personally would probably use OSC, but that has more to do with the fact that I am confotable with it. It may not be the best technical choice!

Yes, you can configure the router as an Access Point (AP) and to assign a static IP to the Arduino. Then you should be able to establish a connection to that AP. I don't have an Androind device but several Apple devices e.g. An iPad and iPad. There you select Settings and WiFi and you will be presented with a selection of available routers. The pocket router shows up there and you should then be able to connect to it.
As the next step you may want to use a the Webserver example from the Ethernet library and see if you can get the Arduino to serve the very little web page. If it does then you have verified that your Android can connect to the Android device.

After that its simply a matter of collecting data and sending data per UDP (or any other suitable protocol of the TCP/IP) to an open port of your choice on the Android device.

Thanks for all your informations ! Well, I thought that I could avoid to have the IP of the arduino written in the code (static) because this is very ugly, that's the only reason the router stayed on my perspective list. Is that possible ?

Sure. Everything is possible:

http://gkaindl.com/software/arduino-ethernet

The Arduinio will run a DHCP client and will receive it's IP from a DHCP server. That'll be either the router of the existing network you will connect the pocket router to (pocket router in Bridge/Client mode) , or it will be the pocket router itself (in AP mode).

Then of course the IP address that will be assiged to your Arduino is subject to change. So you need a method to tell your the application on your Android device. Apples implementationon of ZeroConf technology called Bonjour can do that. Bonjour on your arduino will register a service on the network that you application will be able to pick up. Your network devices (router, Android) need to support Bonjour though.

Most Routers do, but I remember that some time back getting Bonjour is not easy on Android devices. But it's been quite a while since I looked at it alst and it may have changed. Naturally that all works flawless if you stick with Apple devices.

If you intend to use the pocket router in AP mode anyway the DHCP/Bonjout approach is really overkill. Hard coding an IP address that you only use in the Arduino <-->pocket router <--> Android network is really not an issue.

Thank you so much !

You really made my mind clear about all this story and understand a lots of things. I will go through all the documentation and pick up a solution, but now I understand better issues.

Thanks a lot again !

What if I don't want the IP address of my wifi shield to constantly change. Is there an other solution besides mac binding?

What if I don't want the IP address of my wifi shield to constantly change.

Then you probably don't want to be using WiFi. When I connect my PC to my wireless network at home or at work, I get a new IP address each time. It has never once made a difference.

PaulS:
Then you probably don't want to be using WiFi. When I connect my PC to my wireless network at home or at work, I get a new IP address each time. It has never once made a difference.

It does make a difference if the Arduino acts as a server. In that case the clients would not have to change the IP address every now and then.

It does make a difference if the Arduino acts as a server. In that case the clients would not have to change the IP address every now and then.

That's what dns is for. The router should be updating a dns repository every time it assigns an address to a named device. The clients then access the device by name, and dns determines the IP address that corresponds to that name.

Oh yeah.. of course. Thanks :wink: