ericw...@gmail.com

unread,
Aug 26, 2014, 10:05:48 PM8/26/14
to mitappinv...@googlegroups.com
I have an Arduino project with a TV outside of the room running an Android box. I recently decided I could take this a step further with the HC-06 module, which had the potential to display messages on the TV. I hit a snag when I figured out how hard it is to get the communication going. I'm pretty fluent in Tasker, but sadly there are not BT data options. I looked at getting a 1sheeld, but they are still developing their Tasker integration. Then I discovered AI2, and its ability to send/receive BT data. Did some more research, used the ActivityStarter to send messages to Tasker, then hit the "background activity" wall that everyone else has hit with AI2. It would only work when my app was in the foreground. Bummer. But I finally figured it out! AI2's SaveFile saved the day! The app will run in the background and still trigger Tasker events.

In AI2:
Add a File item, it's in the Storage tab
In your event block, add a SaveFile block
text is whatever text you want saved/sent to Tasker
file is the file name, /file.txt will save the file to the SD card (makes it easier to find in Tasker)

In Tasker:
New Tasker Profile > Event > File > File Modified

Click the magnifying glass to browse for your file

New Task > File > Read File

Choose your file, give it a Variable name (I used lower case, use upper if you need this to be a global variable to use in other tasks/profiles)

Then add whatever tasks you want! The variable you set will allow you to perform tasks based on the data sent from AI2/Arduino.

In the task you want to trigger
click the If checkbox > click the tags icon > select your variable > type in the ~ text (~ means your text matches the variable)

Now, even if your AI2 app is running in the background, it will save this file with whatever text you tell it to. Tasker will know this file has been modified, will read it, and will trigger a task based on the text. If there's an easier way to do this, please let me know. I couldn't find anything other than the ActivityStarter, which doesn't work in the background. Also, if anyone needs help using AI2 with the Arduino/Bluetooth combo, I would be more than happy to help!

kurar...@gmail.com

unread,
Aug 27, 2014, 1:33:37 AM8/27/14
to mitappinv...@googlegroups.com
hi! i want to receive data from arduino using app inventor like string of characters (i.e. when I turn off the led in arduino, the arduino will reply the text "led is off") .The text "led is off" will be displayed in the cellphone. What blocks in app inventor is needed?

ericw...@gmail.com

unread,
Aug 27, 2014, 2:18:07 AM8/27/14
to mitappinv...@googlegroups.com

First off, you'll need a Bluetooth module (HC-05 or HC-06). You can use AI to bring up the BT menu for pairing, but I just paired it before I got started. Once you get your phone paired with the HC-06, you can approach this one of two ways: choosing the device to connect to through AI, or specifying the device MAC. I'm only ever going to use this one device, so I just specified. 

If you want to be able to choose the device:

If you want to manually connect to a device when your app starts:

And to receive Bluetooth data (I set my clock to 500 ms):

I hope this puts you on the right track!

kurar...@gmail.com

unread,
Aug 27, 2014, 2:24:31 AM8/27/14
to mitappinv...@googlegroups.com

Tnx for the reply, I already done in connecting my Arduino to android using bluetooth module. In receiving data, do you need to use the clock or not?
my block is like this. I send data to arduino, the arduino will reply back


ericw...@gmail.com

unread,
Aug 27, 2014, 2:31:11 AM8/27/14
to mitappinv...@googlegroups.com
I'm not sure if the clock is required, but I think the Arduino will only send the BT message for a short time. So having the clock basically always listening I think helps.

richardvansoest

unread,
Aug 27, 2014, 9:44:03 AM8/27/14
to mitappinv...@googlegroups.com
Hello, i use an arduino 2560 MEGA to dim the lights in my room (2x 5 meter RGB led strips)
And when i start a film on my XBMC media pc (behind my tv wall) the lights start to dim as the film begins to play, and fade up when the film is ended (or burn at half when i pause the film)

I used wifi for the comunication from AI2 to the PC running XBMC (python based)

on the same pc i have made an Delphi 7 program that works as a server. and sends the recieved commands from my phone to the arduino who controls the lights.

i have made the comunication two ways (every second my phone ask the server for the STATUS)

so i can see if lights are on or of even when not in the room (only on wifi)


program wil not crash when more phones ask the status every second. 

when 3 phones with app running and one person is tapping the lightbulb on screen it fades on or off and on all other 2 phones the picture is updated imidiatly



When interested or have somthing to say about this, feel free.

Taifun

unread,
Aug 27, 2014, 9:55:05 AM8/27/14
to mitappinv...@googlegroups.com
But I finally figured it out! AI2's SaveFile saved the day! The app will run in the background and still trigger Tasker events.
I'm not sure, if I understand what you are saying
are you saying you send some text via Bluetooth from Arduino to an App Inventor app (which is running in the background) and the app stores the text in a file using the File component while running in the background?
Taifun

ericw...@gmail.com

unread,
Aug 28, 2014, 1:33:25 AM8/28/14
to mitappinv...@googlegroups.com
That's exactly what I'm saying. It's kind of a crude way of doing it, but I couldn't get anything else in AI2 to work while in the background. The only other thing that I found that still works in the background is the SendText block, but Android boxes don't have a SMS function, so it just errors. Using the ActivityStarter will work with Tasker, but it requires a Tasker exported Task App, and only works when AI2 is the active window. This means if you have Tasker open another app, AI2's triggers will stop functioning. Using the SaveFile method doesn't need the Task App, and still runs with any app being active.
Reply all
Reply to author
Forward
0 new messages