2014년 12월 5일 금요일

App works via companion but crashes when downloaded to device


I seem to have issues with apps running via companion but not after downloading. In my case (please keep in mind I am a neophyte working with app inventor) I took an app authored by a fellow Arduino enthusiast (with permission) and modified it to my needs. The purpose of the app is to control an Arduino controller via Bluetooth. The app is fairly simple; used to attach to a Bluetooth interface to control devices attached to an Arduino mc. The app was originally written using app inventor classic. After having problems I went back to classic and made the mods I needed and it ran fine via  the classic companion to my LG Lucid2. I downloaded both to my PC and directly to the phone and installed the app; it ran perfectly. Satisfied with my first project success, I felt I should do it with AppInventor 2 in the event classic was taken down. I edited in the block editor the same functions, and again they ran fine to the LG Lucid2 via the companion. But this time after downloading to the PC, (not seeing a way to download direct to the phone), then installing it, the app crashed at a point where a Bluetooth selection was to be made from "listpicker".. Reiterating that when written with the block editor in AppInventor classic, and downloaded it works. I still have that version on the phone. The app also works using AI2 Companion to the phone. It however does not work when downloaded and installed on the phone.

--
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.


--

Thank you for the timely reply Taifun, as stated block editing is very new to me, so I am at the start of the learning curve. That being said, the app is pretty basic and quite short, so I captured the entire block edit to give you a start to finish concept. I did add some additional things in AI classic but this is the basis of the issue. Again thanks for help and inspiration..

--
see here
how to connect correctly

--
I for sure appreciate any help, it will take me a while to digest this, since 1. as stated working with app inventor is new to me. (as well as bluetooth)  Since I "inherited" the portion of the app that connected with  HC -5 bluetooth module from the original author I assumed it was in correct form. (and it did work)  2. I don't understand why it works using both App Inventor classic, and AI2 using the associated companion, but does not work when downloaded after writing with AI2 block editor. I was hoping for not only a resolution to the issue, but an answer to that question as well.

--
Taifun, no offence but I don't think we're on the same page. My goal is to connect one way to a bluetooth module that will interface with an arduino controller. This has been done many times by many people using App Inventor classic. It Does work! There is also a very similar app on the tutorials at http://www.appinventor.org/bookChapters/chapter12.pdf that uses a very similar approach. What you presented to me seems to be way more than required to achieve the goal at hand with tons of overhead.

--
see also this thread https://groups.google.com/d/msg/programming-with-app-inventor/r9t9UWsxZ6k/iS6XBeAjgD0J
probably there is still a bug in App Inventor 2 concerning the evaluate but ignore result block? Why not just connecting correctly?

This is the correct method to connect to a Bluetooth device:
if BluetoothClient.Connect ...
then ... <successful connect>
else ... <error>

see also the documentation http://ai2.appinventor.mit.edu/reference/components/connectivity.html#BluetoothClient

boolean Connect(text address)

Connect to the Bluetooth device with the specified address and the Serial Port Profile (SPP). Returns true if the connection was successful.

Please prepare an example aia file as simple as possible which shows this issue. This would help MIT to fix it. Thank you.


Btw: which error message exactly do you get?

--
Most users here do not have arduino devices.  What others in the forum asked and how some of the solved issues is here:  https://groups.google.com/forum/#!searchin/mitappinventortest/arduino    It appears no one with a device or experience is around to test your code.


You could search in the forum using the Search for topics box to the right of the colorful google at the top of this page  using terms like arduino  or bluetooth     or search for app inventor arduino or bluetooth  on the Web and found other links.


Have you used the DoIt debugging tool to help yourself?  You can read about self debugging here: http://www.appinventor.org/bookChapters/chapter15.pdf 

I do not know why you app fails.   I hope you can figure it out with the suggestions above.   Perhaps Taifun's suggestion would work?  Otherwise, you are going to have to find a solution by experimenting; trial and error.

Best luck.   When you find a solution, please return and explain to us what the issue might have been.

--
Thanks for the response. Again I must reiterate that the procedure  built on has been around and used for quite some time. Even the tutorial I sent a link to doesn't go to the lengths of the example presented by "a simple bluetooth chat. IMHO that seems like a lot of overkill.  This is not a 2way "chat".The object here is to simply connect to the arduino via a bluetooth module, and sent a 1 byte instruction; the issue is not arduino:, arduino is simply the receiver of a byte then makes a decision of what to do in accordance with that byte. In this case: if byte =0 send a 1 second "high" pulse to gio pin X; if byte=1 toggle gio pin y. Again I must reiterate it works using App Inventor Classic. (where the original code was built ). Last night I went back into classic and added a proper app shutdown statement, and again it worked perfectly, linked with companion, and downloaded to the phone. Forgive me if I sound argumentative, I'm not trying to be, just trying to get the point across that there is a difference between AI classic, and AI2. The app works well written in classic, so I guess  I will continue using it, until it's either taken down or I begin to understand why so many apps have been written, and function using this method. Again thanks for your help.

--
Thanks for that Taifun, I will work to incorporate that into the blocks edit and see how it goes. Connecting "correctly" seems to be a subjective term. I will however follow your lead/advice to see if it makes a difference, using the if statement test. (again thanks for that). This situation calls for a 1 way 1 byte communication to a device that offers no response. Not a "chat". As stated many are using it (or were in App Inventor classic) (and it works). Again It works on AI2 when connected to the phone via companion. (it is the packaged, installed apk that doesn't work). I don't get an error code, as I originally stated, the app simply stops at the point the bluetooth device is selected in listpicker and returns to the screen prior to launching the app. The screen capture I attached previously indicates where this appears to be happening. I don't think I have downloaded .aia for the app in question in AI2, (I will do that and place it in my next post) and not sure if I have a similar project downloaded from AI CLASSIC ( I realize their format is different). Would you care to see that as well?

 Last night I went into "classic" and added a proper app shutdown statement, successfully tested via companion, and packaged and downloaded to the phone and all worked well.

--
"This is the correct method to connect to a Bluetooth device:
if BluetoothClient.Connect ...
then ... <successful connect>



See insert :
else ... <error>"

Lloyds_Garage_Manager_bigllodA12.aia

--
After much searching, I found this :

"This is the problem with 'Evaluate but Ignore result'
MIT is aware of this and have put in a fix and should be in the next release.

--


댓글 없음:

댓글 쓰기