2017년 4월 29일 토요일

Dweet Pro


Has anyone sucessfully used DweetPro.io with App Inventor 2?
I can get it working in postman, and freeboard with no issue.
I am not 100% sure how to format the request headers.


--
remove the double quotes


any link to the api documentation?

-- 
Same thing with or without quotes.
Documentation seems lacking.

The boss was able to post with his development software, WinDev.
Even he cannot do a GET.
Where to put the Lock Key seems to be the issue.

It no longer works in Postman either, but it was yesterday.  
I may have to get help from DweetPro.io.

-- 

Same thing with or without quotes.

which same thing? what is the response content?
use Do it to check, if the url is correct, see also tip 4 here
and keep the double quotes removed...

-- 
I think it is Dweetpro.io.  It doesn't even work on their website.
We can post, just not get.
I get;
Content   Session has expired, please re-login  
Code       400
Type        application/json

same error in postman and on their website.

-- 
OK, I finally got it.
The Key needs to be appended onto the URL for locked files.
This could be a great service.  Only $2 per lock (a month I assume).
Once they get the historical data part working, watch out. 


-- 
I got it.
Key must me appended to the URL.

-- 
It works.  The key needed to be appended to the URL.

-- 

2017년 4월 28일 금요일

Domotic API Call


 have made several apps with App-Inventor but now stumbled upon a problem I have not yet found a solution for.

I am trying to get my Domoticz (home automation) system responding to an app.
However I do not get the API call working properly.
Any suggestions.

Here is the link to the API documentation:
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Get_all_lights.2Fswitches

So basically what I am trying to do is this:

http://192.168.1.2:8080//json.htm?type=command&param=switchlight&idx=99&switchcmd=Off When I enter this in a web-browser (using the right IP number and IDX for the switch) my switch nicely turns off. Now what I would like to have is some code that does this when I push a button on my screen. Would also be nice to get the list of devices in my system in a database using this: /json.htm?type=devices&filter=light&used=true&order=Name Anybody any idea ??? --
use the web component together with your URL 
and then call the Web.Get method
use the web.GotText event to receive the result

--
This is what I Tried and only get the error:
Unable to get a response

When I paste this code right into my browser it works.......
So the Ip is ok and the json string also.

Sorry made a mistake in the original post
should be a single "/" before the json part just like above in the blocks.


-- 
sorry, I have overseen, that you are using a local ip and port 8080
this probably does not work? see also: API connect through port 8080


-- 
I changed port 8080 in Domoticz to port 80 and made sure this was working

Then altered my code in Mit App-Inventor and no luck,,,,,

Next step I tried to access from global IP number (not local) and also no success.
Anybody around with Domoticz experience ???

-- 
Thanks for your prompt reply's  anyway......

-- 

Next step I tried to access from global IP number (not local) and also no success.

global ip without port should work...

-- 

Found it !!!

The code should be as the blocks show.

However IP adress should not be the local IP adress. But the IP adress for accessing Domoticz over the internet.
The Username and password need to be invoked in the command as shown and they need to be coded base 64.

The code shown here works !!!!

-- 

API connect through port 8080


Greetings, I want to connect to an API in PHP but using port 8080 ( or whatever different to 80 ) , and can not ; I returns error 1101 (no response ) and shows me that the URL is correct , for example 192.168.1.55:8080/test/miapi.php . The strange thing is that if I do using port 80 , works properly !. What am i doing wrong?

--
PS if I test in the emulator , it works !! It is not in the smartphone

--
Is your API hosted on your own computer?
Is the 8080 port open? Some old routers need to open it manually in the admin page (192.168.0.1 or  192.168.1.1)
Did you allow that port in your firewall?
If it's working in port 80, why you can't use in that port?

--

Orientation Sensor 160426


Hi, I am using a Lenovo TB3-710 tablet that has an accelerometer sensor. I tried downloading a compass app and kinetics sensor app as per the forum below but it still doesn't work. When I tried to download the compass app it says that the tablet doesn't have a compass sensor, is this the problem?

orientation sensor works on some devices , and doesn't for others

--
Problem as to why my orientation sensor doesn't work I mean. Anything basic that I am trying to do on my app with the orientation sensor doesn't work at all.

--
Did you check your tablet's specs? Does it have the sensor? If your tablet doesn't have the sensor, there's not much we can do here.

-- 

When I tried to download the compass app it says that the tablet doesn't have a compass sensor, is this the problem?


it seems to be, your device does not have an orientation sensor?

what happens, if you try the suggestions from sstephan: orientation sensor works on some devices , and doesn't for others

-- 
Hi Italo, the tablet has a GPS and accelerometer sensor, am confused because other android mobiles that we are using such as the Oppo, Samsung Galaxy Nexus and Xiaomi, don't have orientation sensors in their specs and yet it works. Would it be that for the orientation sensor to work it needs accelerometer and compass sensor? I am reading also that it needs a GPS received.

Hi Taifun, i tried all the suggestions from sstephan and it didn't work :(

Thank you both for replying :)

-- 
Most tablets have an accelerometer, some tablets do not have an orientation sensor and/or a GPS,   GPS receivers are only available on the more expensive versions of tablets.

A GPS is a Global Positioning Sensor receiver.  It is not an orientation sensor.    An accelerometer is not a orientation sensor.   An orientation sensor is built-in hardware 
that interacts with the Earth's magnetic field.

Here is a link to the orientation sensor documentation for App Inventor 

You can check to see if a device has an orientation sensor by using the OrientationSensor.Available property.   If querying results in false; the device does not have an orientation sensor or the sensor is inoperative.

Properties
Available
Indicates whether the orientation sensor is present on the Android device.
Do the check.  Some tablets DO NOT have an orientation sensor...what is needed for a compass app.    If the app you downloaded requires a GPS and your tablet does not have a GPS the app might work under WIFI or NETWORK which will 'fill in' for the GPS in a LocationSensor call.

-- 
thank you this helps.

When i buy an android device though, what should i look out for in specs? As none of the specs these days would say "Orientation sensor". Should it be compass sensor?

-- 
The key words would be either Orientation sensor  or  magnetometer. What hardware is provided is up to the manufacturer.  Often the product documentation is incomplete.

If a device has a GPS, the manufacturer will state it has a GPS, if the maker does not brag about a GPS, then it probably does not have a GPS.  The issue of having an orientation sensor 
probably is more complex.  Almost no manufacturer will say their device does not have an orientation sensor.

If the device is very inexpensive, I guess it will lack certain hardware features.  If unsure you might go to the manufacturer's web page and ask if the device has a magnetometer or orientation sensor..they might tell you.

-- 
ok thank you

-- 

how to get a delay timer


i want my app to show an image for 5 secs then hide again after the timer ends. this will happen when a value of 3 is the answer in a calulator. but i cant seems to do this

--
Create a clock component with 5000 ms. When the value is 3, show the message in a label. After that set the timer to enabled.
Inside the Clock.Timer event, set the message label to " " to delete it and set the timer to false.

-- 
i tried doing this and it didn't work. the image isn't displaying

-- 
Post your blocks.

--
so what i got is. when answer = 3 it will trigger a timer that should display the image for 5 secs. after 5 sec the timer should end and then the image will hide it self again. but i cant get the image to hide after 5 secs of it being up it will just stay  there

-- 
how do i show my blocks

-- 

how do i show my blocks

-- 

how do i show my blocks
search for screen capture here in the forum

-- 

2017년 4월 27일 목요일

Check Internet Connection In App Inventor


Checking connection is very easy. You can use a Web component and try connecting to a website. Google.com is a very good candidate for that since it’s very unusual for google server to be down. Below is a snippet where I have a button and when you click the button, it tries to connect to google.com. You can download the project CheckConnection and try changing the google url to something that doesn’t exist and see the result. Say if you set the value of the variable googleUrl to http://www.google.com/1234/5678, you will have a 404 error. If the responseCode sent from the server is 200, that means you have connection.

For a list of response codes and what they mean, see HTTP status codes.



Here’s the project source – CheckConnection



How disable "1101- Unable to get a response" error message from Web component?


Hello, anyone know how i can disable the "1101 " error of the web component, if my phone is not connected to internet?

--
use the Screen.ErrorOccurred event to catch that error, see also

--

Web got.file on device give error 1101 but in emulator work good


I try to download a file with the block web Got.file and when i try tthe code with Companion on my phoe it work good, when i build the apk and i try to download it i receive the error message 1101.
I think it's a problem of App Inventor Building cose i have try to do a new app just with a button for download a file and i receive the same error 1101, just building the apk, on companion it work...
The same code in the same app work when i have try it with AI1 worked good.
Sorry for my bad english, but i really need some help...
(the code is the same of this tutorial page: http://puravidaapps.com/filedownload.php)
thank you for your helps.

--
does the example work for you without modifications?
you can download it here Download aia file for App Inventor 2

--
I have the same problem, when web Got File startet he say cant find file i recive error message 1101.
And i added new screen in existing app and when i start him he crash but work fine under emulator

--
@Vedran: 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.

--
i have dowloaded your .aia file, i have loaded it in my AI2 and i have build the app...
Same problem, Ai2 give me error 1101...
Now i think is a issue of App Inventor builder...
This aia file work in your devices?

--
I just tested the example successfully
probably an issue with your internet connection?
--
sorry but have you tested it with an emulator or on a device with the apk? Cose on AI2 connected with Ai Companion at my phone it work, just when i build the apk and i install it on my device it don't work, and the connection is the same.. For try it i have try to connect me to a friend's wifi and with my 3g phone connection too... Nothing, i have the same problem.. (error 1101)
Would you try to reload your aia file in AI2 and (re)build the apk and test it on a device please?
Thank you for your attention.

--
you are right, downloading a file using the web component doesn't work anymore after building the app.

logcat output 

I also tried to download an image from my own web server, this also failed! 

@MIT: please find an example project attached. Just build it and run the apk file, then click the get button and the error 1101 appears. Thank you.
--
Thank you Taifun for your help

--
Thanks.  Any idea when this started happening?

--
I just built the example on the extension test server and it works fine, which means, it's another V145 issue... 

--
I'm looking into this now...

--
I have found and fixed this bug. It should be in tomorrow's release.

The problem was caused by our updating minSdk from 3 to 4. The Web component writes to external storage (aka the sdcard) which requires READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE. However it didn't have those permissions. It used to work because those permissions were introduced with API 4. So when we set minSdk to 3, they were implicitly granted. But when we updating things to minSdk of 4, things broke.

The Companion worked because it has those permissions because they were added to the File component at some point and the Companion has all components built in so it gets all the permissions.

--
We just deployed release nb145b which fixes this issue.

--
Yes now it work, thank you so much for your helps.
--

2017년 4월 26일 수요일

Web component screen.ErrorOccured NOT trigerred when using DIRECT IP over mobile


How to replicated the problem:

1. Set your phone to work on mobile data, not wifi.
2. Create a Web component.
3. use When screen1.ErrorOccured to catch worng URL responces (error 1101)
4. Set URL to a specific address (e.g. 192.168.2.15) that does not exist, not text.
5. call Web.Get.
6. Event  screen1.ErrorOccured is not triggerred!
7. Disable data on the phone. Event ErrorOccured is then immediately triggerred!
8. Repeat from step 1 on Wifi. ErrorOccured is triggered.
9. Change URL to "ljfdh.dfsdg.sdgfsd" (does not exist). ErrorOccured is triggered
Any idea why and how resolve?

--
Please prepare an example as small as possible, which demonstrates this issue and add the project (aia file) into this thread, so someone can take a look

--
Please see aia file.

I simply took http://www.imagnity.com/wp-content/uploads/2013/03/CheckConnection.aia 
CheckConnection.aia as example and replaced "www.google.com" with 192.168.1.15.


PLEASE MAKE SURE TO TRY IT USING MOBILE DATA AND NOT WIFI. Over Wifi it is ok.


--
Excellent example!

Guess the following might be the cause:

When you are using Mobile Data, and access 192.x.x.x, you are attempting to connect to a local network on your ISP's network. This is usually blocked by ISPs and you'll get a connection timed out error when you try to access it over any browser.

When you are using WiFi network, this refers to another network (intranetwork) on the Same PC Network, the router refuses the connection, and hence this triggers the error 1101.

Changing the IP address to 127.x.x.x does trigger the error block, and therefore I think the above explains this. This also explains why, when you disconnect the mobile data, the error block is triggered. The web component is waiting for a response (indefinitely) and when the mobile data is turned off, this error occurs, and triggers the 1101 error block.

Just a tip: in your example: You've used Label4 and Label5 so as to center the check button. This can also be done by setting the HorizontalArrangement1's elements to be centered by AlignHorizontal Property to Center.

--
Thank you for the explanation!
I would have expected Web component to have timeout like the browser does...Even a configurable timeout would have been preferred.

Anyway, what I am trying to do is access a local device. I want the app to check if I am on the same subnet of the device. If yes, access it via intranet. If not, via Internet (and port forwarding). Any idea how can I do this switch-over automatically?

--
I would have expected Web component to have timeout like the browser does...Even a configurable timeout would have been preferred.
The web component doesn't have this funtionality, unfortunately.

I want the app to check if I am on the same subnet of the device
If you can use extensions, you can use the WiFi Manger Extension to get the Local IP of the device in the conneacted network. May be this can be used to determine?
The extension is available here:
http://puravidaapps.com/wifi.php
com.puravidaapps.TaifunWiFi.aix
wifi.aia


The App Inventor Extensions are currently in testing. See the announcement for more information and read the App Inventor Extensions Document about how to use an App Inventor Extension.
You have to use the extension test server together with the corresponding companion app. You can download the companion app from the Help menu -> Companion information. This doesn't have the android permission to change_wifi_state (WiFi permission) and you'll get an error. However, the compiled app should work fine.


If yes, access it via intranet. If not, via Internet (and port forwarding). Any idea how can I do this switch-over automatically?
I'm sorry, I don't have experience with them, and so I cannot help you. If the device has a server set up and responding at that IP, the web component can be used...

--
Thank you.
Will look at the proposed extension.

I hope timer will be added to Web component..... 

--

HTTPS support on WEB component


I use App Inventor for my personal use and as training tool on Makers and Internet of Things courses.
In particular, I frequently use Web component, which is fine for training purposes, but not so much for my personal use.
In fact, my typical application is to build an APP sending HTTP requests to a web server running on Arduino Yun or Raspberry located in my home. The purpose is to remotely command or check some devices while I'm out of the house.
Obviously using HTTP protocol I have several doubts about the security of my APP.
Is it planned a new component like Web component able to send HTTPS requests?
Of course I could write an extension from Web component... but before starting this not trivial job I want to be sure that official support for HTTPS on App Inventor is not under development.

--
the web component also can send https

for example see my OAuth examples here https://puravidaapps.com/tutorials.php#oauth or the Dropbox example https://puravidaapps.com/dropbox.php

--
Probably my problem is caused by the fact that Arduino Yun has a self-signed certificate.
On Web component of App Inventor I receive an "Error 1101: Unable to get a response with the specified URL: https://<yun ip address>/<resource>".
But if I use WebViewer component with IgnoreSslErrors flag to true, I have no problem on display the same https url
Any idea on how to accept self-signed certificate on Web component?

--
I have assigned this as issue #791. We will look into providing a property for the Web component to have it ignore ssl errors (presuming that is the problem here, we need to investigate a bit more).

--
Do we know what IoT  clients/services do about this?

--

search for Error 1101 with WEB component


Probably my problem is caused by the fact that Arduino Yun has a self-signed certificate. On Web component of App Inventor I receive an "Error 1101: ...
The web component is waiting for a response (indefinitely) and when the mobile data is turned off, this error occurs, and triggers the 1101 error block.
use the Screen.ErrorOccurred event to catch that error, see also. How to check Internet connection by Saj. Taifun.
I have found and fixed this bug. It should be in tomorrow's release. The problem was caused by our updating minSdk from 3 to 4. The Web component ...
Step-2: From under the "Connectivity" menu in the palette, click and drag the " web" component into the viewer. Step-3: ... You have to be connected to the internet when the screen is opened, else you'll get a "1101" Error message.
yes, I also get error 1101. probably they have some kind of protection running to avoid people downloading their lyrics? Taifun.
I've narrowed it down somewhat. When I manually type in the same address and send it through the web component it will go through. It is when I use ...
error 1101 normally means, there is no internet connection, you did not get any response at all from that URL. The Web Component doesn't have an ...
ERROR 1101: Unable to get a response with the supplied URL ... After a lot of testing this ... IMHO there should be a "IgnoreSslErrors" option like in the WEBVIEW component, so it can overcome this 'feature' and work has expected.
I am trying to use a local mysql database to store and retrieve data but when I want to connect I get this: error 1101 unable to get a response with the ...


Dates in app inventor


Hi friends, I have a problem, and I can´t solve it
I have two dates, one from the datepicker and one from the current date, what I want to do is to have the diferences in days from one date to other.
I made the blocks and it work, but for some dates i goes wrong, for eg. today is 6/3/2017 and pick the date 11/03/2017 and it work.. but if I pick 15/3/2017 I have worng answer...356 days!!!.
What do you think that I am doing wrong?


--
see the documentation and define fecha_fut accordingly
http://ai2.appinventor.mit.edu/reference/components/sensors.html#Clock


InstantInTime MakeInstant(text from)
Returns an instant specified by MM/DD/YYYY hh:mm:ss or MM/DD/YYYY or hh:mm. An example text input is "06/22/2015 12:18"


also you could simplify a little bit, see screenshot...
and: use Do it to debug your blocks, see tip 4 here
Top 5 Tips: How to learn App Inventor

-- 
Thanks Taifun for your help, I don´t undestand where is the problem.... I define the variable as dd/MM/YYYY


Also, I simplify as you recommend : 

But still not workin ..

-- 
if you take a look at the documentation, you will realize, that the MakeInstant method needs the format MM/DD/YYYY  and NOT DD/MM/YYYY

InstantInTime MakeInstant(text from)
Returns an instant specified by MM/DD/YYYY hh:mm:ss or MM/DD/YYYY or hh:mm. An example text input is "06/22/2015 12:18"

-- 
15/3/2017 is the third of Marchtember,  the 15th month of 2017.

-- 
WOW!!! TAIFUN you are the best!!! many thanks.....

-- 
Even if it is working now,  you will not get the right number of days for every dates. eg. 09/15/2016 - 01/01/2004 = 4641   - you'll get 4640.

-- 
Alternatively, you could use DateUtils extension that uses much less blocks, auto-calculates leap years and, to my opinion, simpler to use.

-- 
I loaded your days.aia file and I get 4640. maybe this (android) bug is only in the european (german) date format.
I found, that I get correct results by adding 12h.


here is a screenshot from a test app  which shows the wrong dates 

--
Thanks a lot for the help!!. You are awesome!

--
@Rudolf: if you calculate the duration in hours, whats the difference then? 1 hour? probably it's a daylight saving time issue then?
which Android version are you using?

--
Maybe it's an International Date Line problem, like 
in Around the World in 80 Days?

What's the time zone and date setting in the device or emulator?

--
yes it is 1 hour diff.


using
Samsung S2 -  Android 4.12
Tablet - Android 4.03
Tablet - Android 4.42

time zone:

just testing dates between DST 0 +1h     (give me 20 min)

--
ok
what happens, if you try to get the duration between 01/01/2004 and 01/11/2016 (i.e. a date outside of the daylight saving time)?

--
you are right

it is the DST  

DST starts in Germany at march , 26   2.00am -> 3.00am

and then starts the 1h difference.

and ends October, 29   3.00am -> 2.00am

and i got the day back

So everything works, if you add 1h (i did 12h) to the date difference (in ms) . That is how I solved the problem.  And now I learned why ;-)

--