arduino yún PLUS android smartphone MINUS TouchOSC

Dear Sir or Madam,

I would be obliged if you could help me.

I would like to control some LEDs with my android smartphone and an arduino yún. I read a lot about TouchOSC and I also tried to control the LEDs with that. It worked perfectly. :-)

But now I would like to develope my own App with Android Studio without controlling it via webside. I have already started to programm the basic structure. But I am not sure whether this will work or not.

I imagine the project being like this:

  1. Arduino Yún and the Smartphone are both logged in the same WLAN. To be precise, it is the WLAN of the arduino yún.
  2. Now I would like to press the Button "LED on" on the Smartphone.
  3. The LED turns on.

I think I have to programm the following things: a. an App with Android Studio b. an programm for the Linux part of the arduino yún. I think it is in python, isn't it? c. an programm for the arduino part of the arduino

So my questions: :)

Is there anything missing?

Would it even be possible to control the LEDs via smartphone WITHOUT bluetooth? I have only seen solutions with bluetooth when I googled it. :(

Have you any experience in controlling LEDs with the arduino and android? Is the realisation very difficult?

I am looking forward to hearing from you soon. :)

Thank you in advance. :)

Christiane

Even though the phone is connected to the Yun's WiFi access point, you will still need to open a communications channel between the two devices. Most of the Bluetooth examples you have seen probably set up a virtual serial port between the two devices. You will need to do something similar, but over the network.

Your Android app will need to open some sort of network connection. This could be a TCP socket on a specific port, where the phone app and Yun app would talk back and forth directly to each other, much like the Bluetooth serial port examples. In this case, you need a service running on the Yun to accept TCP connections on that chosen port. This could be done on the Linux side, written in a variety of languages (including Python.) Or, you could handle servicing the incoming connection directly in the Arduino sketch using YunServer and YunClient.

Or, your Android app could make a series of web requests which are handled by the web server on the Yun. The Android app would make requests using curl() or whatever similar untility is available on Android (I've not developed for Android, so the details are left up to you to figure out.) You have many choices on how to implement the Yun's side of such a scheme:

  • Use a CGI script written in PHP, Python, or many other languages
  • Use a web service framework like node, Bottle, or Flask (or many others)
  • Use a URL of the form arduino.local/arduino/whatever where the Arduino sketch can handle it directly using a YunServer/YunClient combination (like in the Bridge Example
  • Use a URL of the form arduino.local/mailbox/whatever where the Arduino sketch can handle it directly using Mailbox.readMessage() as is done in the MailboxReadMessage Example
  • Use a URL of the form arduino.local/data/put/key/value to write values to the Bridge which can then be read with Bridge.get(key)

The first three options make it easy to return data to the Android app as part of the request. Options 4 and 5 don't support doing that directly, but you could return data by using Bridge.put(key, value) and then read the data by making a request to arduino.local/data/get/key to get that one specific data value, or arduino.local/data/get to get the values of all keys currently stored in the Bridge datastore. Of course, this technique can be used as an extra mechanism with any of the above options, not just the last two.

As you can see, there are many ways of doing it over the network.

If you run a simple web server on the Yun (the Python Bottle web framework is easy to use) you can display a web page on the phone without any need for any Android programming and you can make LEDs go on and off to your heart's content.

This EzScrn demo may be of interest. And so may this Develop on PC, deploy on Yun

...R

Robin2: If you run a simple web server on the Yun (the Python Bottle web framework is easy to use) you can display a web page on the phone without any need for any Android programming and you can make LEDs go on and off to your heart's content.

This EzScrn demo may be of interest. And so may this Develop on PC, deploy on Yun

...R

I think he said he doesnt want "webside", I dont know if that means website or browser, but this way is much easier imo than developing android.

Anyway, if you develop android, you can talk with the yun via wifi (no bluetooth required). And you dont even need to program python, because the yun api restful server example is enough to listen to tcp sockets.

Dear Sirs,

thank you very much for your long and detailed answers. I was very pleased. :)

I also have a number of supplementary questions. ;)

@ShapeShifter "Your Android app will need to open some sort of network connection. This could be a TCP socket on a specific port, where the phone app and Yun app would talk back and forth directly to each other, much like the Bluetooth serial port examples. In this case, you need a service running on the Yun to accept TCP connections on that chosen port. This could be done on the Linux side, written in a variety of languages (including Python.) Or, you could handle servicing the incoming connection directly in the Arduino sketch using YunServer and YunClient."

I have a question on the last point. :)

If I handle the incomming connection directly in the Adruino sketch using YunServer and YunClient I don't need a programm for the Linux Side of the Arduino. Did I understand that correctly? Can I imagine the Linux Side as a special "tool" which passes on the entered values of the smartphone to the Arduino Sketch and which does nothing else?

@Robin2 Thank you very much for your answer. I would like to realize the project without a webpage. But thank you for the links. They are very useful to know. :)

@mart256 You are right. :) It's "website" and not "webside". I always thought that "webside" is the correct english spelling. I will write "webpage" in future to avoid that mistake. :)

I have also some questions about your answer. :)

I don't have to programm python? Really? This is good news. :) The App on the smartphone must communicate directly with the Arduino Sketch. Is that correct? Can I ignore the Linux part of the Arduino then? Or do I need a programm which passes the entered values (Light On) to the Arduino?

@all I wish you all a nice sunday evening. :)

Christiane_123: @mart256 You are right. :) It's "website" and not "webside". I always thought that "webside" is the correct english spelling. I will write "webpage" in future to avoid that mistake. :)

I have also some questions about your answer. :)

I don't have to programm python? Really? This is good news. :) The App on the smartphone must communicate directly with the Arduino Sketch. Is that correct? Can I ignore the Linux part of the Arduino then? Or do I need a programm which passes the entered values (Light On) to the Arduino?

@all I wish you all a nice sunday evening. :)

The arduino sketch can work the linux side for you thanks to the bridge library.

Check the bridge examples that are included in the arduino yun ide, there is an example called rest api, that sketch creates a server that listens to tcp sockets.

Christiane_123: If I handle the incomming connection directly in the Adruino sketch using YunServer and YunClient I don't need a programm for the Linux Side of the Arduino. Did I understand that correctly? Can I imagine the Linux Side as a special "tool" which passes on the entered values of the smartphone to the Arduino Sketch and which does nothing else?

Yes, the Linux side will actually accept the connections, and pass everything through to the sketch. The necessary code is already in place and set up for you. It is indeed possible to do everything in the sketch and not have to write any code on the Linux side.

There are two ways to do it: as mart256 mentions, a REST API is rather straightforward to set up. An example of that is the Bridge Example shows how this can be done. Of course it can be customized to your needs, and can do a lot more than simply turning pins on and off. With this example, the YunServer/YunClient are working in concert with the web server that is built into the Linux side. When the server sees a web access with a URL that starts with /arduino/ right after the Yun's IP address, it will open up a connection and pass everything that appears after /arduino/ to the YunClient. To send such a command to the Yun, it will be necessary for your Android app to make discrete web requests to the Yun. You can do this manually using a web browser, or your application will have to call the right code to make the request. On many computers, the function curl() is available to do that, but I don't know what's available on Android.

But there is another way to use YunClient/YunServer, and that is as a simple TCP socket server. In this mode, the YunServer listens for connections on a specific port, and when a computer connects to it it creates a YunClient, very similarly to the way the Bridge Example works. The difference is that this is not a web request, but a TCP stream (similar to Telnet.) In this case, your Android application would open a TCP socket to the Yun, and then it would have a persistent socket connection that does not go away at the end of the request - it would stay open. You could send messages back and forth indefinitely, just as if it were a serial port. To use this mode, you change the YunServer call to include the desired port number that it should serve, and you change setup so that it calls server.noListenOnLocalHost() instead of server.listenOnLocalHost() -- not the addition of "no" to the function name.

Now, while you can do it all in the sketch, and ignore Linux, you will be missing out on a lot of the power of the Yun if you do it that way. The Linux side brings so much more to the table, and gives so many more abilities, that you really should stop and take some time (when you have a chance) to learn what it can do. It really does open up a lot more power and capabilities.