2017년 3월 18일 토요일

Error With Emulator


Hello, i have tried to create a piece of code for my GCSE Computing course work and i have seemed to come across an error that i do not understand how to fix. The codes purpose is to allow the user to book computers for any room listed on the map. But every time i go to make sure that the code i am using works  i get a warning telling me that opening audio input failed, this should not be occurring because i do not have any audio in my program. 
The emulator then proceeds to run and it all seems to be fine until i go to use the emulator, when i do this i get a connection error or i get the error message "The application MIT AI2 Companion has stopped unexpectedly. 
Please try again. What would be causing this issue?If you would like a 
screenshot of my code then please do not hesitate to ask. 


-------------
<data:image/png;base64,

iVBORw0KGgoAAAANSUhEUgAABQAAAA
QACAIAAAAx8WMUAAAgAElEQVR4nOy9
Z3QUV7r3W9/uXe+
9Z531vuu9d617jifAzBgfj8EREQfbH
MMcYzBBIMAGY4IxCAwKIAmkVk7dkjp
3K6tzjkpICJEkdXeFViBJwmTb2AaEU
AIUOGfuh11VXalbLSFsnxnX+
i1W1VN779rPrt1i/+
vZtQtK0vYmaXuStD1Jmp5j2u5jmp5j
up7j2p5jmu5j2u7j2p7j2u5kXXeytj
tF252i7ebpunm6K6n6K2mGK2n6K2nG
y+mGSxmGixn6rgx9V7q2PV3bnqnzZ+
n9WTosS4tm65BcPZqnR/KMKN+----------------------------------------------------------
c0EsOFjwO
z/7wAO/
uAAlkOPIUmJAUz6HhLpPViGAUwUAsC
mGNhEAPNN0a8Qh2RTjgqb9heix8iQg
YXstUKer/
DzANHQQNG3oeIxG8RTEiSzU6VLc2Re
BfKgUkXMdmVKlSq9WpW1W7Vpryp7ty
qpShm1TRFYKufnyxZlSp02iu2jRN+
tF34ZKBzoJ+
CuAQFMd6sFAEwjAjDy6C90YBgCsHst
w70W0O87ApivFy/hCrQ1+
ugvCYAF2HkvOvBz40NgmME1BgCMvf8
ZqV/
jADbZwJg3geFQAMYaGF6E1gMYfR20N
XYITABg/
SI0EYCZBADeRTcbwFkWv2Zbzsq2nJV
jNSvH6vdN1N/
zaHPy6HPyGfPymfOLWAuK2M5bOM4l7
Pn5/w/C+
JTP5E8UtwAAAABJRU5ErkJggg==> 

-------

missing_filename

--
Very strange indeed the audio message Zachary.    Help us with a little more explanation;  When do you get the audio input warning?  When your Projects shows on the Designer screen or when you click  Connect > Emulator?            I do not know what is causing something like this.  It is on a school computer?  Perhaps you have multiple windows open on your browser?     I would try using Chrome..there might be something in the browser cache triggering this message.

The emulator then proceeds to run and it all seems to be fine until i go to use the emulator  Do you mean, AI2 instead of the red emulator?

Failure of the emulator to run can be due to many things.   Do you have Companion 2.24 loaded on your PC.    Try  Connect > Hard Reset  ; if a pop up menu appears, follow directions to update the Companion (Companion works with the emulator).  If a menu does not show, you probably have 2.24.

Now the fun begins.  Well, not fun, but the reading... here are a lists of reasons a Project might not load into the emulator.  The most common is #1 , 2 and 3.   If the issue is not one of these, yes a screenshot would certainly help someone to provide more advice.

One of the following  possibly applies to your code (all may not apply to your code):
1)  You have coding errors in your blocks.  In the Blocks editor, look in the lower left corner of the window for the yellow and red triangle icons. If the red icon has a value larger than 0, you have a serious coding error.  Find the block in your code that has a red triangle and fix it.   Red triangles always inhibit creating an apk or running a project in the emulator or possibly creating an aia file.     Yellow triangles are more forgiving, however, sometimes, these need to be fixed because they trip an internal warning and not filling puzzle piece sockets that are left un-filled can sometimes cause issues if the app needs a value that is not filled.

2) Your source file (the aia file) is larger than the 5Mb limit allowed in AI2 (the aia can not be larger than 5Mb). You may have put images or other resources in your Media (resources) that you do not use in the app. All the images and sounds in resources count toward the 5Mb limit along with the source code.    You can program apps larger than 5Mb in the browser, but the apps will not compile and might not run in the emulator or the project may not save as an aia. If this is the case you need to reduce the size of your image and/or sound files.   Most image files can be made quite small by resizing them using a photo manipulation program on your PC to less than 50Kb each.

3)  You might have more than 10 Screens in your app.  AI2 becomes unstable when more than ten screens are used.  Projects CAN be built with slightly more screen but then you should expect your app to occasionally behave erratically.

4) You might have set a Screen icon in the Designer Properties for your project that is too large. Use an image sizeof 48x48 px  instead and only use jpg or png images.  *.ico files are not supported.  The 'icon' (actually an image) Google Play requires when posting needs to be 520x520 for their display.  The smaller 'icons' work for the app's icon (the one shown on the device's screen that is pressed to activate the app.

5) You did not code the entire project using App Inventor 2.   If you used one of the third-party AI2 clones,you might not be able to load a Project into the AI2 compiler or create an apk with the standard AI2.

6) If you incorrectly modified the project's Manifest files using a third-party tool, you may have issues.

7)  Sometimes, if you have LOTS of Layouts on a single screen,  the apk might not compile. How many is a lot?  I do not know, keep adding layouts and buttons, compile and try again...when the server crashes, you got a lot.

8)  The network you use may be overloaded (possibly a school network), or you have other applications running in the background on your computer, or your virus checker is doing a scan.  Sometimes, just trying to access the MIT server a few minutes later will give you a more favorable response.

9) Do you have BlueStacks on your home PC (BlueStacks is a special emulator that allows Android apps to run on a PC)?  The Google emulator on AI2 cannot run unless BlueStacks is disabled and all of the BlueStacks processes are shut down.  On a Windows PC, you use the Task Manager to 'kill' running processes.

10)  Are you using Sensor controls (except for the clock)?   Most Sensor controls or controls related to sms or the phone do not work in the emulators.  This includes the LocationSensor and Accellerometer.  These components need to be tested on a device.

11) If this is an issue about the Project loading slowly on your device or on the emulator:  Be aware, the more images, layouts, components you have on a screen, the longer it takes for the emulator and Companion to render the graphical screen.  How fast the emulator renders is partially a function of your hardware...how much ram you have, your cpu clock speed etc. Sometimes, with lots of graphics, the emulator will just give up.   Can you develop live using WIFI or using USB? These options almost always render faster than the emulator but will not be at lightning speed if you have lots of graphics.  Be patient.

12)  This happens too:   We have seen instances where it is probable the Google Cloud messed up; other instances where an older PC has had memory issues and caused file corruption of the Project and instances where a user is using a very slow Internet connection (like dial-up) and it is just too slow.

13)  Do you have an AVG, Eset or AVAST virus checker.  Some versions of these products have been reported inhibit running the emulator unless (in the case of AVG) the Advanced Link settings on the software are set to allow AI2 communication.

14) Do you get the error:  The blocks area did not load properly. Changes to the blocks for screen xxxxxxx_Screen1 will not be saved. One users had this error, the problem was he had too many comment boxes exposed at once for the browser to handle.  Try minimizing all blocks, and opening in another browser,like Chrome or Firefox.

16)  Having issues getting AI to run at all, perhaps your firewall is blocking.  Don't turn your firewall off, just allow AI2 to pass unhindered..some firewalls have the ability to allow or deny certain urls.

17)  If you get a build server busy ... In this particular case the buildservers were just well, busy! If you get this message, just try the build again.  MIT currently run 3 buildservers all the time. They occasionally add a 4th or even a 5th. There is a load balancer which distributes work to the buildservers. If you get the "busy" message, either the load balancer could not find a buildserver with available resources or the the buildserver it assigned the request to decided it was too busy.  The solution is to just try again, either immediately or in a few minutes.  If this message persists, then something might be broken and you can report it on the forum.   If something IS broken, MIT will find out about it soon enough!

18)  If you have excessive resources, you can look at what is in the emulator. In both in the Companion via WiFi and in the emulator, with the emulator "up" you should be able to go to: http://127.0.0.1:8001/ on the PC running the emulator. Going to that url should show you a small (possibly empty) directly listing (it will be a list of the assets that are used in the emulator).

19)  You might have used an alpha character in the app's Version number.  The version number must be all numerical digits.  Use of an alpha character will spawn a generic error message on attempting to compile. If the connection times out, that is a problem! The aiStarter program uses the "adb" program (in the "commands-for-AppInventor" folder) to setup "tcp port forwarding" from the PC to the emulator on port 8001. This command could be failing for you. Make sure you don't have security software that is blocking the action of the "adb" command.

19)  The problem could be something else, like running an old version of Companion ...if this is the case the cure might be:   Projects > Hard Reset.  If there are Companion issues, a pop up will appear (if no issues, nothing will happen...just smile).  When the pop up appears, follow the instructions very carefully, then reboot your PC and try again.

20) If this is a connection issue with WIFI: If the device is set up to be used with USB, the Android cannot be used with WIFI unless the Settings > [developers options]  in the Android  box next to  USB debugging is unchecked.  Some users try to use their phones BOTH with USB and WIFI.  That can be done.  To use the live development USB option the developer must have the USB debugging box checked.  If developer later wants to use WIFI the USB debugging box should NOT be checked.

21) Parse Error:  The most common cause of a parse error is the device has run out of storage.   Do you have  lot of apps on your emulator?  Try freeing up space there (clear the TinyDB perhaps-TinyDB.ClearAll), and see if that helps. 

22)  Do you have lots of Windows open on your browser or are you streaming music or video?

23) Large bmp files ( 1 to 2 MB in size, 800 x 1500 pixesl)loaded into a button the is 50 x70 pixels will cause Companion to fail when loading a project.  The issue is AI2 must compress these to the small size to make them fit in the small area.  The solution is to make these files 50 x70 pixels (or however large they must be in on the Android).

Are you up and running with the emulator after considering the above. Please let us know.   If you are not, tell us more and someone can provide additional help.

--

Bad arguments error related to gas sensor app


I have attached the screenshots displaying the error aswell as the blocks in which it is displayed. In that block stating " if label5>=label 10" -- label 10 is the block below the slider where i can set a specific value ; when this value will be equal to the value in label 5( which is the block below the text "SENSOR VALUE" which shows live data from sensor) then a voice command is supposed to play saying " gas leak".
Instead just after getting connecting it displays the " bad error" message

doubt1.jpg 표시 중

doubt2.jpg 표시 중

doubt3.jpg 표시 중

doubt4.jpg 표시 중

--
We need to see more blocks to diagnose this.
That > operation does not occur in your post.

Do a "download Blocks Image" on a blanks spot of the Blocks Editor to get them all.
For good measure, also include the .aia export,
and the sketch generating the data.

-- 
I have included the files you asked . Please come up with a solution.



-- 
and the sketch generating the data



It looks like your transmitting side is sending multiple readings at a time.
Show us the transmission code.

-- 
See attached for my best guess without seeing the transmission code.

Since the  incoming readings are listed vertically in the error message
I infer they are being sent with a println(), so a delimiter is needed
in the BT Client of 10.
(10 = LF in decimal.)
So I set the delimiter to 10 and asked for -1 bytes in the ReceiveText,
to get just 1 println() worth of data at a time.


Capture.PNG 표시 중


-- 
Yes it is sending reading from the sensor continuosly , is there a problem in that ?




-- 

Yes it is sending reading from the sensor continuosly , is there a problem in that

That's not a problem,
as long as you use the delimiter and try to read twice as frequently  as you transmit.

-- 
I looked at your .ino sketch.

You are blasting out readings as fast as posssible, with no delay between them.

See the examples in my FAQ for how to slow down the .ino transmitting side with delays.
(FYI - Ai2 has no delay capability, just clock events).

-- 
It's all in the .aia I posted a few posts ago.
Download attachments .aia,


Project -> import from my PC ...

See attached if you want to do it yourself.
Turning in for the night, 11 PM here.

Capture.PNG 표시 중


-- 
Thank you so much . I made the changes you told and now the prior errors are gone and the app works fine now but there's new issue at hand.
1) The APP CRASHES after 3 mins of use .
2) I am using a slider to adjust the threshold value going above which the app does give the "LEAKAGE ALERT",that part is fine. Now i want my arduino to recieve the values set by the slider in the app so that when the "alert message " is given by the app , the LED would also glow at the same time.I cannot figure out how to do this.

These are the two current situations for which I need help  !

-- 
For reading the value from the slider, your sketch must be able to receive it. For example, it should start with something like this:

void loop()
{
  //Receives commands from remote computer:
  if (serial.available())
  {
    int inByte = serial.read();
    serial.println((char)inByte);

    switch ((char)inByte)
    {
      //Actions:
   ...

For finding the cause of your crash, you should post your newest set of blocks.
-- 
I forgot to post the link to my FAQ, with its
Arduino and Bluetooth sample section: Arduino and Bluetooth

Also use the search facility in this board for "gas sensor".

-- 
Sorry , I had been away due to some family emergencies. I have attached my recent blocks. The crashing issue has become much more troublesome. The slider gets stuck after 2-3 times of sliding it and then the app crashes. PLEASE HELP! My project is due tomorrow!




-- 
I have two suggestions...

Regarding the Slider position changed event, it may need an extra layer of indirection in
its actions, to deny it any possibility of getting "stuck" trying to something that may hang.
To do that, I suggest adding an extra global variable, LastSliderPosition, initially 0.
Whenever the slider position changed event fires, do nothing.
Move the processing of a new slider position into the clock.timer event block,
guarded by an if/then test of the currrent slider.position value against LastSliderPosition.
If the slider hasn't changed position do nothing, else update LastSliderPosition and send the new value
of the slider position over the wire.

Secondly, add a speech queue to avoid asking the speech component to talk again
while it still hasn't finished saying its previous message.
Use the .AfterTalking block to service the queue.

Third, I see you are sending at a rate of 20 ms per reading, but reading at a rate of 1 reading per second.
Is the data piling up in an AI2 buffer 50 times faster than it is being processed, causing the crash?
I suggest copying the BTbytesAvailable value to a label each time it is taken, for a clue.
Does the value keep increasing, suggesting a big backlog that needs to be flushed?

-- 
"copying the BTbytesAvailable value to a label each time it is taken," - can you be a little more specific ,sir.

-- 
To test my mental model of how BlueTooth delimiter blocking works, I coded my suggestions.
I also speeded up the AI2 timer to 200 ms, just 10 times slower than your sensor.
But I do not have a device to test them, so I leave that to you.
Let me know what happens?

See attached blocks image and .aia file.



-- 
I just came up with another hypothesis for your slider crash.

What if the same antenna circuitry is being used to receive and send BlueTooth data
and it needs time to switch between receiving and sending?

Is that a consideration?

-- 
Sir, I dont think the circuitary will be an issue as we use bluetooth to send and much more data than this. As far as sendind and receiving is concerned ,i think it is internally designed to use seperate channels for it. 
I have attached a video. The app isnt crashing anymore but s new problem has been added. It is saying "gasleak" even when the current reading is below threshold , this problem wasn;t there earlier.



-- 
Sir, I'm really stuck up.Waiting for your response .

-- 
In the video you uploaded I saw (since the values were not clear,I guessed them. So correct me if I'm wrong) that it showed GAS LEAK alert only when the sensor reading was above the threshold level . It showed gas alert only when you set the level to 101 (I guessed this since it was not clear) and the sensor reading at that time was around 109,110.

-- 
Yes sir, that is the idea but if you see the video till the end you will find that when I set threshold to 246 and the sensor reading shows 109 ,although it displays "System secure" it still keeps on saying the message " Gas Leak". That is the current problem.

-- 
I neglected to have the clock timer clear the speech queue 
when it detected a normal condition.

To clear the speech queue variable, set it to empty list.

-- 
I see my backlog label shows 2000 bytes of unread messages piled up
in the BlueTooth Client.

You may notice I added a Click event to your unused Button1,
to clear both the speech queue and maybe the BlueTooth Client backlog.

I suggest adding the .Text "Reset" to that button
and trying it.

From the video, your app still suffers from an ever increasing backlog
in the BlueTooth Client that needs to be addressed.

-- 
you said "I also speeded up the AI2 timer to 200 ms, just 10 times slower than your sensor." Can you explain it to me why am I slowing it down, my sensors already displaying values fast enough, shouldnt I speed the AI2 timer to get par with the sensor? The concept is not really clear to me.

-- 
Fresh versions attached.


-- 

you said "I also speeded up the AI2 timer to 200 ms, just 10 times slower than your sensor." Can you explain it to me why am I slowing it down, my sensors already displaying values fast enough, shouldnt I speed the AI2 timer to get par with the sensor? The concept isnot really clear to me.



When I received your .aia file, it had the clock timer set to 1000 ms per cycle.
Your .ino had an inner loop of 20 ms, so that was a sending to receiving
ratio of 1000/20 = 50 transmissions to 1 reception.

I sped up the .aia timer to 200 ms, to give it a chance to run for a while, but
also for my ulterior motive of giving messages to pile up (if that mental model of
how it works) was correct.  That's also why I added the extra label to show bTClient.BytesAvailable
to see if bytes piled up waiting to be read.  That confirmed my hypothesis.

So it's okay to set the AI2 clock to 20 ms to match the transmitter.

But I can't guarantee the AI2 device will be fast enough to finish its work
before the next timer hits.

(In my FAQ on this board there's a section on timing with info from the
AI2 creators, more reliable than me.)

I think it would be safer to slow down the transmitter side to 40 ms,
and receive at 20 ms.
There's a data transmission law about the speed ratio, 
whose name I can't remember at the moment.

-- 
So, should I set the AI2 timer to 20ms and give a delay of 40ms in my Arduino code?

-- 


So, should I set the AI2 timer to 20ms and give a delay of 40ms in my Arduino code?



Yes, try it.

But also watch that new BytesAvailable label, to see if your AI2 side is keeping up.

-- 
I used the recent .aia file. The maximum value of slider is set to 200 though the sensor shows around 300 and it doesnt speak anymore. See for yourself, I've attached a video.


-- 
The video was very short, but I managed to get a glimpse of the gas reading stuck at 200.

So it looks like the AI2 side has to leave its fishing net in the BlueTooth waters longer,
to get a fish before pulling it out of the water.

So try both at 20 ms, or both at 40 ms.

The final solution might be to leave the ai2 net in the water to collect a backlog,
then periodically empty the net.

-- 
Its 3 am 18th March over here .I will try it tomorrow morning.


--
I will be going offline for a day or two soon, so I throw this thread up
for whoever is available.

-- 
(self flushing added to BT buffer and single-message speech output added)
Going offline



-- 
I followed this discussing in the beginning, but I did not reply, because I had other things to do, I do not want to be pressured by projects due tomorrow, (that is your problem, not mine), and I do not want to be addressed as "sir".

It is however quite clear why your app keeps saying "gas leak": Your sensor transmits much faster than AI handles it, and at each timer event only one message is read. Therefore, at next timer events yopu will read "old" messages for a while and these are still saying that you have a gas leak.
For the AI side to keep up, the timer interval must be shorter than the interval the BT device is sending things, and long enough to handle incoming readings.

Then, there is another thing: what is the usefulness of sending gas readings every 20 or 40ms? It takes at least 2 seconds = 2000ms to say the message "gas leak". If this app is only meant for giving warnings to human beings, the interface could use human timings.

These two reasons would suggest to set the delay in the sensor to at least 1000ms and in AI to about 500ms.
I will take a look what effect the speach component still has.

-- 
you were right about the delay timings. The problem is solved .Thanks

-- 
Great! Cheers, Ghica

--

Work-arounds for external writes (but not really)


While designing an audio engine I found myself in a place where my assets had grown exponentially and I was running out of internal space. Let's use the external sd card. But how? Research led me to Taifun's File Tool. If at first you don't succeed, and all that... You get a list of valid locations, find out which ones and in what ways are they writable... And believe me, i've tried it all.



Method 1: Cash Out

I was already in a place where I was downloading the assets on initial use... so if I couldn't get it off the internal and onto the external, then I wouldn't even download it, 'cause i'm stubborn like that, i'll stream it. However, this left me with a cache full of  audio files that eventually clogged my internal storage... same problem.

Here's how I solved this particular problem: (Download the attachment)

This gets you to a place on your device where you can access the settings for your app, so you can clear the cache.

Note: may not be a viable option for any particular scenario.

I used it as a way to relocate the large amount of accumulated data to another area of the internal structure and give the end user a more readily accessible way of managing those files.

Please take notice that this method will increase data usage overhead; but as programmers... these are the choices we face.

as a side-note: Intelligence, the work-around for ignorance.

--

TaifunFile1 Write to External


VALID STORAGE LOCATIONS:



Writable External Locations:

Must manually create directory with actual name of your app.

E.G. appinventor.ai_MxyzptlkHavok.fileTest
Final writable locations from testing results

CONCLUSION:
Need a way to MKDIR() or MKDIRS() [JAVA]
an activity starter perhaps [com.android.????]
end users who have to: 1. manually create directories, or, 2. rely on external apps, is inconvenient

if an app were able to be activityStarted with "appName", and in return, create only those directories; then, return those directory paths...

Notes: 
your paths may differ from mine, as well as your results...
but in my opinion, an app can only write to its' own folder in one of these three locations:
1. "android/data"
2. "android/obb"
3. "ext root"

sidenote:
would it be possible to get your zip extension for testing?

--
using my file extension, the directory should be created automatically in case it does not exist
that's interesting!

are you able to use the Copy block to copy a file to directory file:///storage/ext_sd/Android/obb/appinventor.ai_MxyzptlkHavok.fileTest/ on the external sdcard and at the same time creating that directory in case it does not exist? 

As you probably have seen, I'm not able to test this, because I do not have such device and for some the message "permission denied" occurred while copying to the external sdcard  

which device and Android version did you use for your tests?

btw. my zip extension is now available to download here https://puravidaapps.com/zip.php

--
TEST TRIAL 2

Test bed(s):


DEVICE 1
device: rooted HTC 510 desire
android version: 4.4.2
htc sense version: 6.0
htc sdk api level: 6.25
kernel version: 3.4.0
shinr...@shinru2004-MS-7693 #1
SMP PREEMPT
baseband version: 1.101.1372.19.0725_10.22.4205.00L_F
build number: NonSense Beta 1.01

ext_sd: Samsung 128 EVO+ Micro SD XC I
notes on test bed: non-stock device setup, custom rom, custom kernal


DEVICE 2
device: stock HTC 510 desire
android version: 4.4.2
htc sense version: 6.0
software number: 1.11.506.8
htc adk api level: 6.25
kernel version: 3.4.0-gb43dcd3
a...@AABM #1
SMP PREEMPT
baseband version: 1.101.1372.19.0921_10.29.4205.00L_F
build number: 1.11.506.8 CL374695 release-keys

ext_sd: SanDisk Ultra Plus 16GB MicroSD HC I           
Test 1: directory present/not present test
file to copy: test.jpg
dir to create: appinventor.ai_MxyzptlkHavok.fileTest/
locations to create dir in: 
storage/ext_sd/Android/data/
storage/ext_sd/Android/obb/
storage/ext_sd/
Syntax used:
results: 
1. fails with ENOENT if appinventor.ai_MxyzptlkHavok.fileTest/ directory does not exist
2. will not create dir, but will write to if present
Test 2: new directory if directory present test
file to copy: test.jpg
new dir to make: newTest/

locations to write to: 
storage/ext_sd/Android/data/appinventor.ai_MxyzptlkHavok.fileTest/
storage/ext_sd/Android/obb/appinventor.ai_MxyzptlkHavok.fileTest/
storage/ext_sd/appinventor.ai_MxyzptlkHavok.fileTest/

EACCES triggered if directory is not named in accordance to app (this is for trying to write to pre-existing directories).

Conclusions: 
As previously reached in trial 1, an app can only write to its own directory but can't create its own directory
and inline directories will only be created if an app is writing to its own directory. 
However, this test is for writing to external sd cards only, and should not be deemed conclusive for work on an internal structure.

--
thank you very much for your tests!

--