Arduino Bonjour / Zeroconf

Hi Arduino Forum,

[edit: i've changed the original topic to arduino Bonjour / Zeroconf] read last post!

I need some advice on how to approach my idea for a graduation project.
The idea is to create an interface for a device (arduino with sensors, actuators) on an iDevice or other 'pad'.
I want to create the app on the iDevice or 'pad' in HTML5, using websockets. I allready found out that there are
websocket libraries for Arduino:

https://github.com/ejeklint/Arduino-Websocket-Server
https://github.com/krohling/ArduinoWebsocketClient

Also, there's a nodeJS powered allround websocket solution: http://socket.io/#how-to-use

EDIT: after watching [this]: to clarify, i DO NOT want to use a server! either the arduino or the HTML5 app should act as 'server'.

Beneath is a simple diagram of what i want to achieve:


picture hosting

The data has to be able to go around in real-time (i need to poll a sensor quite often)

So i have some questions about this idea:

  • Can i use the websocket libraries using a WiFi shield?
  • Should i use default HTML5 webSocket implementation, or should i go for the socket.io solution?
  • should arduino be the server or client? and more important, why?
  • For prototyping, i can just use local IP adresses which i can find out. but how to let these 2 websockets find each other so to say?
    i mean, is there a way to discover one eachother without having static adresses for each websocket? my solution has to work in every
    standard wifi network :slight_smile:

Thanks!

I think that what will work easiest is to have the Arduino act as a web server, serving up HTML5 pages and initiating an ad-hoc WiFi network. The iPad could then connect to the ad-hoc WiFi network and fetch pages from the Arduino.

John,

I've thought about that way of connecting, but i don't know if i can get data realtime then. It has to be TCP/UDP, not HTTP...
Also, a user would have to first connect to the ad-hoc network (because you cannot do that in code but that's ok, everyone could do that),
but after that, also navigate to a webpage. I really don't want users to have to do that. They have to start an app, which does everything
for them :slight_smile:

Would the iPad and the device be on the same wifi network? If so then one way to do it would be with Bonjour services so you don't need to worry about IP addresses and whatnot and it would be automatically discovered on any network.

supermaggel:
John,

I've thought about that way of connecting, but i don't know if i can get data realtime then. It has to be TCP/UDP, not HTTP...
Also, a user would have to first connect to the ad-hoc network (because you cannot do that in code but that's ok, everyone could do that),
but after that, also navigate to a webpage. I really don't want users to have to do that. They have to start an app, which does everything
for them :slight_smile:

There's nothing to say that the client app on your iPad has to be a browser. You will be writing an app of some sort, and it could communicate with your Arduino web server via HTTP as easily as any other protocol, I'd have thought. HTTP doesn't mean you are tied in to using a web browser to access it. Although, being able to access your Arduino via a web browser will certainly make it easier to test.

@Stevonavich yes, you can assume that! Can i use bonjour services in a HTML5 app? I don't think so right? It should be a IOS app then. This is, however a great contribution because i can state this in my graduation project: If the app were to be developed in IOS, i could use this service to autodiscover the arduino device.

@PeterH: That's true. However, the HTTP protocol is not well suited for real-time data requesting. you need to have a steady, open connection for that (not request, and request, and request) so that's a better reason i don't want to do it that way. But i do think i'm going to let the arduino be the server. Then, the problem becomes: how do i let the app on the iPad 'find' the arduino server (supposing that i don't know the IP adress in another WiFi network).
For prototyping i'll just use static IP adresses (and make it changeable from the HTML5 app) and then state what @Stevonavich said.

Thanks guys! Then if i only could have some answers concerning this question:

  • Can i use the websocket libraries using a WiFi shield? (Has anyone done this before? Is there any difference with a wired Ethernet shield?)

supermaggel:
However, the HTTP protocol is not well suited for real-time data requesting. you need to have a steady, open connection for that (not request, and request, and request) so that's a better reason i don't want to do it that way.

You are completely wrong. There are many AJAX frameworks that use a long-running query to provide a continuous communication stream, and if you're writing the client yourself then ultimately what you're reading and writing is just a character stream; you can impose whatever message format on that you want. (I'd suggest you follow one of the standard SOAP or HTML based protocols, though.)

@PeterH, yes that's true, but i'm not wrong. The HTTP protocol was designed to request webpages, not to provide an open, maintained communication channel. AJAX, Comet and all other long-polling solutions are therefore workarounds imo. So if the possibility exists to just use UDP or raw data over TCP/IP, i'd choose that over HTTP. besides, i'd have to have make arduino understand the HTTP protocol. What for? i don't need the extra layer so to say.
I'm sorry if it was unclear what i needed to start with, hard to express yourself clearly in a foreign language :slight_smile:

What i want is a one-on-one connection using WiFi (ad-hoc or using a standard WiFi home network), to get realtime data from- and send some commands to an arduino device. And, by preference, this way. I also found a 'bonjour' like way to detect an arduino device on a network, which i will look into further. This is, bytheway, not possible using HTML5 right, because webSockets only allow simple communication, not DNS and reverse DNS lookups?

That is correct, HTML5/Javascript cannot do Bonjour by itself because webSockets is far too limited, so you would have to make it a native app if you wanted to go that route. The link you gave to the 'Bonjour like' library would probably work, though it really isn't Bonjour like, and is really quite trashy, I mean really? Just ping every single IP address on the local network and hope one of them responds? It works, but not very well, especially in a large network. Unfortunately, though, I don't know of any way to do zeroconf with just webSockets, so it may be your only option if your stuck with HTML5.

Yes, it IS really trashy. but i wonder if i could do that only once, just to get the attention of the arduino device. then, store it's IP / hostname and then continue using only THAT hostname / IP, that'd be super OK for me :slight_smile:

I'm not really limited to HTML5, but i'd like to target as much mobile platforms as i can. AIR is another way, Haxe is another (cross-compile to all sorts of native stuff). in AIR (AS3) i know there's a lot of raw networking support (socket, socketServer etc.). i think i'm going to do some testing here, see what's possible on mobile devices and what not. i think i'll simulate an arduino capable of WiFi networking with another machine/laptop or even my own mobile phone...

I'll keep this thread updated with my results, if any!

Any additional cases, projects, tips are really welcome!

Okay, i found the following which is interesting for Bonjour / Zeroconf:

Arduino Bonjour implementation

and an AS3 implementation for service discovery | code on bitBucket

So far, i haven't found any other zeroconf solution that would target different devices in a network - not just iDevices.
I only need to know if the bonjour service would work with arduino if it had a WiFi shield instead of Ethernet shield,
i'm trying to contact the author about that. Will keep this thread updated!

That stuff looks good. I've used that arduino bonjour implementation and it only compiled after some editing, but once it compiled it worked great, with the ethernet shield. It hasn't been updated in a while so hopefully the author will respond to you about the wifi, but if not I'm sure it could be reworked to be useable. That AS3 implementation sounds cool to, as long as he does get it available for iOS.

Okay, so here's another somewhat disappointing update:

Using AS3 it's not possible, because Sockets are not supported on mobile.
But that doesn't matter, because Georg Kaindl, the author of the arduino bonjour library, emailed me this back, and i quote:

"So the thing is that I've looked into supporting the popular WiFi shields (there are a couple of different ones, by which I mean different chipsets), but the problem with these is that none of them (at least none that I found) give you direct access to what's going on on the wire. However, Bonjour needs to do some "advanced" things, like joining a multicast group, multicasting, etc..., which these boards do not support.
Typically, a WiFi shield only acts as a serial-to-TCP/IP bridge, but doesn't really give you much control over anything :-/ If you have a WiFi shield that maybe has a more advanced chipset that I don't know about, let me know. In theory, porting to a different command set should be easy, provided that the commands exist."

..that kind of sucks. However, he proposed another solution, using an ethernet bridge (and thus ethernet shield), but my project doesn't really allow an extra bulky, big device to be added (though i could consider it...)

I also contacted Per Ejeklint to ask if his WebSocketServer would work with a WiFi shield and he mailed me this, and i quote:

"I haven't used the library for a while so I can't tell if it works under Arduino 1.0. I used it with the last beta version, 22 I think. But it should be minor differences and easy to update. I see no reason why it shouldn't work with a wifi shield. I will take a look at some point but right now I have no time left. Only boring (but paid) work is on the schedule for a while..."

All in all, the WebSocketServer seems like a lesser risk then the ethernet bridge workaround (i have no way of knowing sure that would work).

To conclude my research i also bugged Stack Overflow with a cross-post }:> Let's see what comes of that...

As for a WiFi device with more control I put in the Wifi Bee (or the WiShield if you prefer a shield):

http://asynclabs.com/store?page=shop.product_details&product_id=26&vmcchk=1

On that one you have a separate AtMega328 you can program with Arduino tools and a minimal TCP/IP stack on top of it. Should be at least the same control level as you get from the WizNet 5100 on the Ethernet Shield.

Thanks for this! Might you know where one could buy a WiShield 2.0? The store in the link you gave doesn't have it in stock anyore?

I don't have a WiShield but I got my Wifi Bees here in Switzerland at

http://shop.boxtec.ch/product_info.php/cPath/59_60_138/products_id/40655

As far as I know the deliver to the Netherlands.

BTW: The shield uses your Arduino as the controller, with the Wifi Bee you get a separate AtMega 328 to do the protocol stuff and you're free to use UART, SPI or I2C to communicate with it.