Friday, February 21, 2020

Installing non-allowed apps on Android

For an index to all my stories click this text

I was doubting wether I would buy an e-reader or a new tablet. My current tablet is on Android 4 and getting so slow that when pressing an icon for opening a program you can wait a loooooonnnnnggggg time before something happens.
Next to that some programs (APPS) are no longer available under the old Android 4 or can not be updated.

I have several uses for a tablet. I use it for reading books and documents I find on the web (mostly technical), as a control station for my Domoticz home automation, and I use it for program- and App-devellopment.

An e-reader can only be used for reading books.

So a new tablet was it going to be.







There are many fancy tablets which will cost a fortune. And I am a cheapskate. So I bought a tablet from Alcatel with a 7-inch screen, a reasonable fast processor, 8Gb storage and 1 Gb ram, USB, Wifi and Bluetooth. Best of all it runs Android 8.1. I added a 64Gb SD-card which was on offer at the local dollar-shop for 7 euro. Now I had a tablet with a lot of memory for a total of 56 Euro !!!!

I started installing all kind of apps which worked flawlessly. And then disaster struck !!!

One of the apps that I use frequently is the IFTTT app. I use it for communication with Google Home and for notifications from my ESP's. I wrote more as 10 stories on IFTTT on this weblog. You can find them in the INDEX PAGE  https://lucstechblog.blogspot.com/p/index-of-my-stories.html

On my tablet I searched for IFTTT in the play store and I could not find it. Now that is very awkward.

At first I thought there was something wrong with IFTTT. So I tested it by giving commands to my Google Home and they worked. Then I started the APP on my phone and that worked to..... IFTTT was fully operational so why did it not show up on my new tablet ??



I used the browser on my PC to access the play store on my PC. I searched for IFTTT and there it was !!



So I logged-in on my PC with my tablets account and password and searched again for IFTTT. And here it came up !! So why not on my tablet ???



There it was: This app is incompatible with your device !!!!

How on earth is that possible. I have plenty of memory on my tablet. A modern processor with quad-core. A reasonable screen and Android 8.1. It should work !!!

I tried the install button om my PC's screen. Maybe I could install it from my PC onto my tablet.



No avail. Install was greyed out and would not operate.

Why ??

Well there are several reasons why you are not allowed to install some apps on your phone or tablet.
Sometimes a developer is not paying attention and defines that an App can only run on Android XXX and later while that is not the case.
A developer can also forget to disable the settings for certain sensors. For example running an acounting package does not need the use of the gyro or compass functions on your phone/tablet. However if the developer forgets to rule these out Google Play thinks you need them for the app and if your phone does not have them then you are not allowed to install the app.
Maybe you are not allowed to use certain apps in your country......

What now ???

Google to the rescue.


Sounds like a paradox. Google prohibits me to install something and I will use Google to search how to avoid their own rules ;)

I know that all Android APPS are first loaded onto your phone/tablet as an APK file and then installed. Maybe I could find the IFTTT APK file somewhere on the web. A google search came up with multiple places on the web where you can get APK files bypassing Google Play. I give you here the links to a few:

APKMirror  https://www.apkmirror.com/
APKPure    https://apkpure.com/
Fdroid     https://f-droid.org/
APK-DL     https://apk-dl.com/
Aptoide    https://www.aptoide.com/

I used APKMirror and will show you how to use that site for getting App's Google withholds you.



So I searched for IFTTT on APKMirror and it came up almost immediate.



From APKMirror I could download the APK file to my computer.

Getting the APK on the tablet

The only thing I had to do now was to transfer the APK to my tablet.

There are two ways to do that.

Install with PC

First thing is to make sure you have Google Drive installed on your tablet and on your PC. A similar service like Dropbox or OneDrive will work alike.

Open Google drive with the browser on your PC and login with your tablets credentials.
Transfer the downloaded APK to Google Drive on your PC.

drive

When the file has been uploaded it will directly be available in Google Drive on your tablet.
So switch to the tablet.

Open Google Drive on your tablet.



Click on the file and download it on your tablet.
It will then be transferred from Drive to the Download folder on your tablet. Open that folder with the Android file-app. Click on the APK file.



Android will give you a warning that this will be an insecure install.



Give permission to proceed.



Now you can install the IFTTT app.

Install with Android.

Actually it is the same as installing the App from your PC. The difference is that you use the browser on your tablet (or phone) and download the APK file directly.
The download will be in the download folder (obvious). Open that folder with the Andoid file-app. Click on the APK file and follow the instructions which are the same as the last steps you can see above.

So there you have it.

This way you can install all kinds of apps on your phone or tablet which are not allowed by Googles Play store.

Caveats and Pitfalls

There is a possibillity that you download a 64 bit app while working on a
Android phone or tablet that has a 32 bit processor. Another problem can be that an app expects certain sensors which are not available in your phone/tablet. These are a few examples that can make an installed app crash.

Despite these caveats this is a great way to try apps which Google does not allow you to install.

Till next time
Have fun

Luc Volders


Friday, February 7, 2020

ESP8266 sending data to Domoticz

For a complete index to all my stories click this text !!

If you have not heard about Domoticz by now it is time you should.




Domoticz is a complete home automation system that is open source and free for you to download. It runs on Apple, Windows, Linux and last but not least Raspberry. You can find the web-page here: http://www.domoticz.com/

My system is running on a Raspberry 2B with some extra hardware called RF-Link. My RF-Link clone an Arduino Mega with a 433Mhz Transmitter and Receiver. This makes it possible for Domoticz to communicate with Klik-Aan-Klik-Uit and other cheap 433 Mhz switches, doorbells, blinds, weatherstations etc.
Domoticz itself communicates with systems like Philips Hue, Sonos, Anslut (Ikea lights), Mi-Light etc etc etc etc. You can find a complete list of brands and devices on the Domoticz Wiki Page:
https://www.domoticz.com/wiki/Hardware

The Domoticz software is controlled from a webpage that can be accessed by your PC and there are Android App's available to control it from your tablet or phone.

You can even make rules like switch the TV on, close the curtains, switch the home-cinema on and dim the lights. So with one button your set for a move evening.

Summarising: with Domoticz you have a complete system to automate your home which will set you back around 60 euro.

I bought some cheap 433 Mhz switches and automated the lights in my hobby room, living room and with christmass I switch on the christmass-tree and all related lamps from anywhere with the App on my phone.

This is all great but I wanted more.

In all the years I am tinkering I build several projects with led-strips, sensors like a rain-sensor, door and window sensors, a thermometer etc. I want them all to be controlled from Domoticz.

Next to that I want to build some special switches. For example a switch with an LDR that tests the light in a room and automatically puts on the lamps when needed. Or a switch that puts a lamp on when someone enters a room. You can do all this with individual switches. But it is neat to have one central place where it all comes together.

As an add-on for Domoticz someone started a project called ESP-Easy ( https://www.letscontrolit.com/ ) that makes it easy to attach sensors to an ESP8266 and connect that to Domoticz. A really neat project so check it out.

However I want to do things myself and presumably you to otherwise you would stop reading from here.

So what I am going to show you here is how a button pressed on the ESP8266 sends a command to Domoticz which then sends a command to a 433Mhz light switch. Great for making remote controls for Domoticz. And next I am going to make a temperature sensor that sends it's data to Domoticz. 


Intermezzo

I am moving away from ESP-Basic. It is no longer maintained nor updated. And there is no ESP32 version available. So I am building most of my new projects in the Arduino IDE (C++). I must admit that writing and develloping programs in ESP-Basic is faster as writing and debugging in C++. There are however a lot of nice sensors and add-ons available now which are not supported in ESP-Basic. So this story will be one of the last ones in which the program is in ESP-Basic.

ESP on screen button as remote for Domoticz

First thing we are going to build is an ESP8266 that creates a webpage on which a button can be clicked that sends information to Domoticz. In my setup I have a 433 Mhz lightswitch that controls a lamp in my hobbyroom which I am going to control this way.









Start with looking in Domoticz at the devices list for the switch you want to control. I wanted to control "Lucs room lampje" which has IDX number 3. We need that number to put in our program.

To control this switch we need to call a Domoticz API. You can find a list off all Domoticz API's here: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's

On this page look for the entry : Turn a light/switch on
There you will find the required API call:

/json.htm?type=command&param=switchlight&idx=99&switchcmd=On

So what we need to do is to build a webpage with a button on it and when that button is pressed this code is send to Domoticz. And that is easily done with ESP-Basic.

For those of you who have no experience with ESP-Basic I urge you to read this tutorial which will have you up and running in no time:
http://lucstechblog.blogspot.nl/2017/03/back-to-basic-basic-language-on-esp8266.html

And here is the program.



cls
wprint |<h1 style="text-align:center;">Luc Volders</br>Domoticz</br>Control|
wprint "<br/><br/>"

button "Lamp on", [domoticzon]
wprint "<br/><br/>"
button "Lamp off", [domoticzoff]

wait

[domoticzon]
query = "192.168.1.66/json.htm?type=command&"
query = query & "param=switchlight&idx=3&switchcmd=On"
ret = wget(query,8080)
wait

[domoticzoff]
query = "192.168.1.66/json.htm?type=command&"
query = query & "param=switchlight&idx=3&switchcmd=Off"
ret = wget(query,8080)
wait

Let's have a look at this.

The program starts with putting some text on the screen and two buttons for ON and OFF.

When one of the buttons is pressed the program jumps to the accompanying routine wich calls the API. As described above the API looks like this:

/json.htm?type=command&param=switchlight&idx=99&switchcmd=On

and that is translated in ESP-Basic in this:

query = "192.168.1.66/json.htm?type=command&"
query = query & "param=switchlight&idx=3&switchcmd=On"
ret = wget(query,8080)

query is the variable in which the data is collected that is going to be send. 192.168.1.66 is the IP number of my Domoticz setup. You have to replce that with your own IP. The rest of the API call is just copied except the IDX number which I altered in the number of my switch: 3

The wget statement sends the API call and puts the answer in the ret variable. You do not need to add this line but if you do not any info that Domoticz send back is displayed on the screen which makes a mess of your screen.

I do not think that it can be programmed in any other language for the ESP more easier.



And this is the result on your computer / phone / tablet's screen.

The buttons Lamp on and Lamp off switches lucs room lampje on or of and that can bee seen in Domoticz and off course by just looking at the lamp.





Temperature Sensor

I also wanted to send some sensor data to Domoticz. So I attached a Dallas DS18B20 temperature sensor to the ESP8266 (NodeMCU board) to see if I could get some readings.

To setup a switch or sensor in Domotics that is not physical attached but gets it's data through wifi you will have to define a virtual switch.


First in Domoticz open the devices tab and create a virtual switch. Give it a name. I choose Virtueel 3 and choose as type Dummy.


Now choose create virtual sensor I gave it as name Test temperature and as sensor type Temperature


At this moment the sensor is already visible in the Temperature Tab of Domoticz although it does not have received any value and therefore the temperature will be 0



Go back to the devices menu (Apparaten in Dutch) and there you can find Virtueel 3 and as you can see that the ID number is 4592

Next step is to build the hardware


My test setup is just a DS18B20 with a pull-up resistor of 4.7K attached to GPIO2 (D4) of a NodeMCU board.

In ESP-Basic I wrote a small test pogram to see if the sensor worked.


cls
wprint |<h1 style="text-align:center;">Luc Volders</br>Domoticz</br>Thermometer|
wprint "<br/><br/>"
wprint "The temperature is now "& temp(0)

wait

Nothing special. The program just reads temp(0) which is the DS18b20 and puts the value on the screen.

Back to the Domoticz API page on the web: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Create_a_virtual_sensor
Here we can read how the API call looks for reading a sensor.

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP

IDX = id of your device (This number can be found in the devices tab in the column "IDX")
TEMP = Temperature

So we just need to implement that in our ESP-Basic program. Here you go:


cls

timer 1000 * 60 * 5, [domoticztemp]

wprint |<h1 style="text-align:center;">Luc Volders</br>Domoticz</br>Thermometer|
wprint "<br/><br/></h1>"
wprint "The temperature is now "
textbox temptest
wait


[domoticztemp]
temptest = temp(0)
temptest = (int(temptest * 10))/10
query = "192.168.1.66/json.htm?type=command&"
query = query & "param=udevice&idx=4592&svalue=" & temptest
ret = wget(query,8080)
wait

Again very easy to implement.

A timer is setup that every 5 minutes calls the [domoticztemp] routine.

Timer 1000 * 60 * 5 = every 5 minutes

The formula is simple. ESP's timer works in miliseconds. So 1000 = 1 second (1000 miliseconds). 60 Seconds in a minute and that times 5 minutes.

Why the 5 minute routine ? Well Domoticz just displays the sensors reading once in the 5 minutes on it's screen.


And there you go: the temperature is displayed in Domoticz.

Last step: Combine button and Temperature

A NodeMCU or a Wemos D1 have many I/O ports. Why not use them ? So let's combine the button and the temperature programs and include a physical button as well.


Again the hardware setup is easy. I took the temperature setup and added a button that is connected with a pull-up resistor (10k) to D3 of the NodeMCU board.


cls
wprint |<h1 style="text-align:center;">Luc Volders</br>Domoticz</br>Control<br> And Thermometer|
wprint "<br/><br/>"

but=0

button "Lamp on", [domoticzon]
wprint "<br/><br/>"
button "Lamp off", [domoticzoff]
wprint "<br/><br/>"
wprint "The temperature is now "
textbox temptest

interrupt d3, [change]
timer 1000 * 60 * 5, [domoticztemp]

wait

[domoticzon]
query = "192.168.1.66/json.htm?type=command&"
query = query & "param=switchlight&idx=3&switchcmd=On"
ret = wget(query,8080)
wait

[domoticzoff]
query = "192.168.1.66/json.htm?type=command&"
query = query & "param=switchlight&idx=3&switchcmd=Off"
ret = wget(query,8080)
wait

[change]

if but = 0 then
query = "192.168.1.66/json.htm?type=command&"
query = query & "param=switchlight&idx=3&switchcmd=On"
ret = wget(query,8080)

else 
query = "192.168.1.66/json.htm?type=command&"
query = query & "param=switchlight&idx=3&switchcmd=Off"
ret = wget(query,8080)

endif

but = 1 - but
interrupt d3, [change]
wait

[domoticztemp]
temptest = temp(0)
temptest = (int(temptest * 10))/10
query = "192.168.1.66/json.htm?type=command&"
query = query & "param=udevice&idx=4592&svalue=" & temptest
ret = wget(query,8080)
wait


No surprises in the software either. An interrupt tests wether the button has been pressed and jumps to the [change] routine.

but = 1 - but

This line toggles the but value between 0 and 1 for setting the switch ON or OFF.

The rest is the same as in the previous programs.


This is how it looks on the screen of your computer / phone / tablet.

Hey, what's that Luc's Room Temperatuur thing ???


Well remember my "Oh no, not another wifi thermometer." entry in this weblog. If not you can re-read that story here: http://lucstechblog.blogspot.nl/2017/11/oh-no-not-another-wifi-thermometer.html


As you might remember this thermometer not only set's its data on the screen of a webpage but it also sends it's data to Thingspeak. To refresh your memory you can re-read the weblog entry here:
http://lucstechblog.blogspot.nl/2017/11/thingspeak.html

Well that thermometer has been sending it's data also for a long time now to my Domoticz setup.

Here is the altered code for that Thermometer.


tel=0
Timer 5000, [start]

wprint "<!DOCTYPE html>" 
wprint "<html> <body>"
wprint |<body style="background-color:greenyellow;">|
wprint |<H1><span style="color: red;">|
wprint " A thermometer"
wprint "</H1>"
wprint "</span>"
wprint |<H2><span style="color: blue;">|
wprint "Temperature is now "
textbox test

a = "background-color:greenyellow;"
a = a & "display:block;width:80px;"
a = a & "border-style: hidden;"
a = a & "font-size: 22px;"
a = a & "font-weight: bold;"
a = a & "color: fuchsia ;"
cssid htmlid(), a
wprint "</span>"
wprint "</H2>"
Wait

[start]

test = temp(0)
test = ((int(test*10))/10)
tel=tel+1
if tel = 360 then
  tel = 0
  gosub [thing]
endif
wait

[thing]
sendthing = str(test)
SENDTS("MY-API-KEY", "1", sendthing)

'and to Domoticz
domoticz = "192.168.1.66 /json.htm?type=command&param=udevice&idx=2662&svalue=" & test
wget(domoticz,8080)

wait

As you can see the temperature is not only put on a webpage accessible from your computer/phone/tablet but also send to Thingspeak like described in this story:
http://lucstechblog.blogspot.nl/2017/11/thingspeak.html

And now it also sends the data to Domoticz, using the same code as described above with just another IDX.


The chart shows you that the thermometer has been working continuously from july 2017. This shows how reliable the ESP8266 and ESP-Basic is.

As stated in the beginning of this story: I am moving away from ESP-Basic to the Arduino IDE (C++). So in upcoming stories I'll be showing you how to achieve this in C++. So stay tuned.


Till then
have fun

Luc Volders