Arduino Yun as a TCP server

Hi everyone, I need to create a WiFi weather station, using Yun and a DHT11 sensor, that sends temperature and humidity rilevation to a Windows Phone mobile connected on the same LAN as the Yun.
I can’t really understand how it should work, I guess the WP device should act as a client, so just send a request to the server using a socket and print the data, while the Yun should be the TCP server that accepts the request and when the connection is established prints the temperature and humidity data via WiFi using the bridge. Am I right? How is it supposed to work? Does anybody have a similar example so I can understand? Because I’m very confused and I don’t think I can work it out without help. Sorry if my english isn’t perfect but English is not my mother Language.

Yep, your Yun is supposed to be a server, i.e. it listens on a port and when a client connects, accept the connection, send the data and disconnect again. If you want to keep the connection open, the client has to ask for more data, but that all depends on your communication protocol.

kind regards,

Jos

I know how to make it work without using the Bridge (see this demo). I know it can be done using the Bridge but I don't know how.

The Yun runs the uHTTPd server - that's how it can produce its management webpages. And you can use that to serve other webpages.

You can host a server on the linux side, and the client can send a GET command, so the server sends a response.

If I use uHTTPd can I show the data via Application or only via browser? Does anybody have a sample code for a TCP server that can interface with mobile applications for the Yun?

fabriziotrovato:
If I use uHTTPd can I show the data via Application or only via browser? Does anybody have a sample code for a TCP server that can interface with mobile applications for the Yun?

Yes, but you should learn to program for mobile first. I have sample code for both. However, at this point I don't have enough documentation. But there is enough if you know how to get the Bridge Tutorial working with LED #13.

My code for Phonegap Mobile is
phonegap-arduino-toggle13

You can download and install a pre-compiled App here:
https://build.phonegap.com/apps/1429804/share

Jesse

For more adventure try this:

Arduino, ProcessingJS and SocketIO in Action

Jesse

jessemonroy650:
Yes, but you should learn to program for mobile first. I have sample code for both. However, at this point I don't have enough documentation. But there is enough if you know how to get the Bridge Tutorial working with LED #13.

Not sure it will work for Windows phone as well as for Android, I'm still confused but thank you anyway!

What if I try something like this?
https://github.com/evothings/evothings-examples/blob/master/resources/arduino/arduinowifi/arduinowifi.ino

fabriziotrovato:
Not sure it will work for Windows phone as well as for Android, I'm still confused but thank you anyway!

@fabriziotrovato,

Phonegap supports Windows Phone 7/8 and the latest. Sometimes they are a little behind fixing things, but Microsoft has stated the will support Phonegap. This is likely because phonegap gap is the basis for other Hybrid system, such Ionic.

Jesse

fabriziotrovato:
What if I try something like this?
https://github.com/evothings/evothings-examples/blob/master/resources/arduino/arduinowifi/arduinowifi.ino

@fabriziotrovato,

Okay. This is a common misunderstanding of the Arduino Family. The Arduino Yun has two processors. On processor is like the Arduino everyone thinks about when they think Arduino. It is connected via serial port to the other processor. The Other processor is a Linux computer. It does the job of a Ethernet, Wifi and USB shield, but it does NOT use the same libraries. So, in theory this works just like an Arduino (that everyone knows), but the wifi and ethernet are different.

So to get back to your questions, the Linux part (a full Operating System) takes care of the network tasks. So you would run your TCP server on the Linux part. And the code you see on evothings will NOT work.

I hope this makes things clearer.

Jesse