Saturday, November 11, 2017

Arduino Project One: Corona hits a roadblock

This project has many different facets, and a lot of new things to learn. Development is definitely not linear. It can go in many different directions simultaneously — and that's a good thing, because some of those different directions run into roadblocks.

The Corona Roadblock

For example, there's nothing that says I have to have the webserver running on the Arduino stack before I start working on the Android app. With that in mind, I concentrated on learning Corona this week. Since I once ran a game programming company, I'm familiar with this genre of software. So it seemed like a safe and comfortable place to go.

I downloaded the Corona SDK and worked through the Getting Started tutorial. The last step was to do a live build, installing a development version of your app on your Android device.

Sadly, it was not to be. When I selected File > Build > Android from the Corona Simulator, I got this error message:
Stupid error message.


I selected Yes, and I ended up downloading and installing Java SE Development Kit 9.0.1 for Windows, 64-bit. (It doesn't give you much choice.) After it was installed, I ran Corona and selected File > Build > Android again. Same error message.

I went to the Corona community forums and found this recent thread, which says that Corona SDK 2017.3135 doesn't support the 64-bit JDK. But a fix is coming, and in the meantime, the awesome Corona staff posted a link to the older, 32-bit, Java SE Development Kit 8u151. The word on the Web is that multiple JDKs can exist on my computer at once, so I'll leave 9.0.1 installed.

Corona's not the only game in town. But I'm comfortable with it, with my gaming background. My son has used it successfully and speaks highly of it. And I really don't feel like downloading, installing, and learning yet another development kit. I already have enough new tools to learn. But I went ahead, and downloaded and installed 8u151.

It works! Back in Corona, File > Build > Android built a .apk file for me.

Then I needed to practice installing it on my phone. The Corona Signing and Building page says that if I don't have the Android SDK installed, I can upload the .apk file to a webserver, then download it to my phone, go to the Downloads directory, and simply tap on the .apk file to install it. However, the Signing and Building page also says that I can use the adp install command to install the .apk file directly.

Two problems arose. First, the debug version of the app was so big that it exceeded (what was left of) my daily limit on my webserver, so detouring through the webserver was out of the question for the day. Second, adb is the Android Debug Bridge, which is part of the official Android SDK, and I inferred from the Corona documentation that adb is rather important.

So even though I didn't want to "download, install and learn yet another development kit," that's exactly what I did. First, I mistakenly downloaded and installed the Android Studio IDE. If adb was part of Android Studio IDE, it was hidden very well. I couldn't find it. Then I looked on the Corona debugging page, and it gave some clues on how to download the command-line-only Android SDK tools. That was a relief — if I had to download the entire Android Studio IDE, why was I even bothering with Corona? So I happily uninstalled Android Studio IDE.

According to the debugging page, I needed to install at least the Android SDK Tools (I had to scroll down to the bottom of the page to find them) and Android SDK Platform Tools. It took some sleuthing to find those links. The adb tool is in the Platform Tools, so I had to make sure I had that one.

I unzipped the downloaded files and stored them in C:\Program Files\Android\sdk-tools, in the subdirectories tools and platform-tools.

For a test, I tried installing the StarExplorer app from the Corona SDK "Getting Started" tutorial. It took a couple of tries to execute the adb install command:
C:\Program Files\Android\sdk-tools\platform-tools>adb install -r "\Users\Ray\Documents\Corona Built Apps\StarExplorer.apk"\Users\Ray\Documents\Corona Built Apps...d. 2.8 MB/s (27069109 bytes in 9.069s)        pkg: /data/local/tmp/StarExplorer.apkSuccess
C:\Program Files\Android\sdk-tools\platform-tools>
Finally it was successful - but then I couldn't find the app on the phone. I looked in the Apps pages, but StarExplorer wasn't there. Then I looked for the /data/local/tmp directory using the My Files app and I couldn't find it.

It turned out that I was being impatient. It just took a while for the phone to update its files. After about 20 minutes, I went back to the Apps pages and I found it. The app ran perfectly on my phone.

To make it a little easier the next time I install an app, I added the paths C:\Program Files\Android\sdk-tools\tools\bin and C:\Program Files\Android\sdk-tools\platform-tools to my PATH environmental variable. Now I don't have to type in adb's entire pathname to run it.

So even though it was a real trip down the rabbit hole, collecting and installing all the tools to build and install the app on the phone, it finally worked.

Corona Does Networking!

On the bright side, I did find out this week that Corona has a network library. Reading the API documentation and looking at some examples, I'd say that this will do the trick nicely. 

So What's Next?

Now I can write the app. Once it's completed, I'll go back to the Arduino. I have to do the following:
  1. get the relay clicking
  2. try out those Hall effect sensors
  3. write the webserver and exercise it from my home network
  4. get my DSL modem / Wifi router to passthrough HTTP requests to the Arduino webserver.
  5. exercise the Arduino webserver from outside my home network

What about Internet privacy?

One thing that I haven't thought about until now: I need to research privacy / security measures for the Arduino webserver. I don't want the whole world to know when my garage door is up or down, and I definitely don't want strangers activating it. Moreover, I don't want someone in Uzbekistan hijacking my Android, turning it into a bot, and using it to mount a DDoS attack on an embassy somewhere.


To read the other postings about this project, click here and scroll to the end.

No comments: