iphone + arduino + wifi shield

hello
1.I want to use iphone to control arduino with servo motor, how to communicate between iphone and arduino?
2.there is a example in arduino called web server (in ethernet shield ),what difference between this method(like send the "http://192.168.1.177/@your angel"to arduino) with TCP protocol?which is better?

HTTP uses the TCP protocol. The advantage of HTTP is that you can use a web browser as a client and don't have to write your own client software. Do you want to write an iPhone app to talk to your Arduino or do you want to use the Safari web browser already on the iPhone?

I would take John's recommendation and use HTTP. As he said, you can use web browser instead of writing an app. It's cross-platform in case you want other devices to access your arduino. Plus, all the user interface is done by browser so you don't have to do any.

johnwasser:
HTTP uses the TCP protocol. The advantage of HTTP is that you can use a web browser as a client and don't have to write your own client software. Do you want to write an iPhone app to talk to your Arduino or do you want to use the Safari web browser already on the iPhone?

No, I dont want use web browser. I want write UI in Xcode, Arduino just receives data.So I am wondering how to build the communication. And there are protocols I know such as TCP, OSC...but I dont know how to build that. Is there any tutorail?

liudr:
I would take John's recommendation and use HTTP. As he said, you can use web browser instead of writing an app. It's cross-platform in case you want other devices to access your arduino. Plus, all the user interface is done by browser so you don't have to do any.

I agree with you, I need to build the interface in Xcode. Is there any easy way to do that? Now, the massage I am sending is like "http://192.168.1.177/@yourAngelData" is
there any good way just sending "servoMotorNum_yourAngelData;servoMotorNum_yourAngelData"like this?or is there any other way better than mine?

What is your background in objective-C and programming in general? I don't know of tutorials (must exist online somewhere) but you can take free iTunes U courses to learn how to program in iOS. I'd not waste my time learning it since that only covers part of the mobile devices. Sorry, no more helpful info from me. I'd be interested in seeing a quick tutorial myself just to see if I can quickly handle it (say a day's work).

pzstar:
I need to build the interface in Xcode. Is there any easy way to do that? Now, the massage I am sending is like "http://192.168.1.177/@yourAngelData" is there any good way just sending "servoMotorNum_yourAngelData;servoMotorNum_yourAngelData" like this?or is there any other way better than mine?

TCP will send a stream of bytes, sort of like Serial, but with the advantage that bytes never get lost. You get to decide what you want to do with that stream of bytes. You can send your data in binary, which is efficient, or you can send the data as text and add framing characters to make it easy to parse.

liudr:
What is your background in objective-C and programming in general? I don't know of tutorials (must exist online somewhere) but you can take free iTunes U courses to learn how to program in iOS. I'd not waste my time learning it since that only covers part of the mobile devices. Sorry, no more helpful info from me. I'd be interested in seeing a quick tutorial myself just to see if I can quickly handle it (say a day's work).

thanks anyway~~

johnwasser:

pzstar:
I need to build the interface in Xcode. Is there any easy way to do that? Now, the massage I am sending is like "http://192.168.1.177/@yourAngelData" is there any good way just sending "servoMotorNum_yourAngelData;servoMotorNum_yourAngelData" like this?or is there any other way better than mine?

TCP will send a stream of bytes, sort of like Serial, but with the advantage that bytes never get lost. You get to decide what you want to do with that stream of bytes. You can send your data in binary, which is efficient, or you can send the data as text and add framing characters to make it easy to parse.

I c ...thanks a lot. how do you think the OSC protocal? Is better than TCP in this case?

pzstar:
how do you think the OSC protocal? Is better than TCP in this case?

I am not familiar with the OSC protocol. If it works over WiFi then, like HTTP, it is probably layered over TCP (or UDP). If it will work for your purposes and will save you the trouble of defining your own protocol then, by all means, use it.

I c ...thanks a lot. how do you think the OSC protocal? Is better than TCP in this case?

It looks like it's an older protocol - Wikipedia says its data wrapped in SLIP wrapped in UDP... I haven't seen SLIP since about 1998....

My $0.02 is: I sure it's a fine protocol if you're already doing MIDI-ish things and can find libraries that you like, go for it. If not, then there's no way it would be worth your time to write your parser for it. It would be orders of magnitude simpler to do something like make the Arduino be a basic web server and interpret URLs e.g. "http://192.168.1.109/?servo=2&angle=135" and have the client issue plain old HTTP requests.

I want to do the same thing... use my iphone to control a servo using an arduino. However I was looking at trying to do it using HTTP or a telnet server. Which one do you think will work better. I have test programs of each method but there are bugs in them and so they don't work. Any Advice?

mattygio:
I have test programs of each method but there are bugs in them and so they don't work. Any Advice?

On the advice side, read sticky post. You need to post the codes, and where they come from, what hardware they assume, what hardware you have. What the intended effect of the code is and what actual effect/error messages you observe. You lack above basics on a tech forum.

mattygio:
I want to do the same thing... use my iphone to control a servo using an arduino. However I was looking at trying to do it using HTTP or a telnet server. Which one do you think will work better. I have test programs of each method but there are bugs in them and so they don't work. Any Advice?

Well..."better" really depends.

Telnet is a simpler protocol to code for the server, since you don't have the overhead of HTTP headers etc. It's basically the same as using the Arduino IDE serial monitor. On the other hand telnet is more difficult to support on your client end (an iPhone) because it's not native and you'll have to do everything with typing on a tiny virtual keyboard.

HTTP is more work on the server side because there's more parsing to do, but it's nicer on the iPhone side because the client is built in (Safari) and you can easily make a UI with buttons and sliders etc. out of HTML elements, no custom client coding required.

As far as debugging advice -- I'd separate the communication code from the action code and make sure the two pieces work. For example, get the servo working how you want via the serial monitor. Next, get the communication between the iphone and Arduino working, again using the serial monitor to verify (e.g. click a form on your iPhone, have the Arduino serial print out "I saw the form click!", etc.). Then combine and enjoy.

Good luck!

johnwasser:

pzstar:
how do you think the OSC protocal? Is better than TCP in this case?

I am not familiar with the OSC protocol. If it works over WiFi then, like HTTP, it is probably layered over TCP (or UDP). If it will work for your purposes and will save you the trouble of defining your own protocol then, by all means, use it.

thanks a lot !!!!!!

There is a lot of speculation here about OSC.
It is a binary encoding that can be is usully sent as UDP or SLIP encoded serial.
You can find a full Arduino OSC library here with plenty of examples: