Suppose someone came to talk to you and said, “I need your help. I have a Raspberry Pi -based robot and I want to develop a personalized Android application to control it.” If you are like me, you will think of updating the updated Android developer tools, and you will wonder if you remember exactly how to sign a manifesto. Not an attractive thought. Of course, you can buy things on the shelf that facilitates the task, but it is not personalized, and you must accept its operation. But it turns out that for simple things, you can use an old Google Labs project which is surprisingly, always active and works well: MIT Application inventor – Who, unfortunately, should have the acronym ai, but I will simply call it inventor to avoid confusion.
What is the inventor? He lives in your browser. You install a false phone screen using drag and drop, a bit as you would use QT designer or Visual Basic. You can change your view and attach actions using a block language a bit like scratch. You can debug in an emulator or on your phone wireless. Then, when you are ready, you can delete an APK ready file for people to download. Do you prefer an iPhone? There is a certain support for that, although it is not as mature. In particular, it seems that you cannot easily share an iPhone application with others.
Is it perfect? No, there are a few quirks. But it works well and, with a little patience, can make incredibly good applications. Are they as effective as a hand-made masterpiece? Probably not. Is it important? Probably not. I think it gets a bad representative because of the colored blocks. It is surely made for children. Well, honestly, it is. But it does a good job, and just like Tinkercad or Lego, it’s easy enough for children, but you can use it to do things quite incredible.
How fast?
How fast is it to create a simple Android application? Once you have used it, it is very fast and there are a lot of tutorials. Just for fun, I wrote a little personalized web browser for my favorite website. It is difficult to say it from the image, but there are several components present. The low web browser is obvious and there are three oval buttons. The Hackaday logo is also clickable (this brings you home). What you cannot see is that there is a screen component that you get by default. There, a vertical arrangement that stacks the toolbar with the web browser. Then, the toolbar itself is a horizontal arrangement (colorful yellow, as you can see).
The black bar at the bottom and the upper bar are part of the false phone, although you can also choose a false monitor or a tablet if you want more space.
What you cannot see is that there are two other hidden components. There is a clock. If you are on the home page for an hour, the application refreshes the page. There is also a sharing component that the Share button will use. You can see three views of the application below. There are three views: a design view where you visually build the interface, a block view where you create code and the final result running on a real phone.
In design mode, the browser does not take care of
Inventor app uses blocks instead of the source code
At the time of execution, my color choices are not as good as I thought
Code
Putting all of this on the screen only took a few minutes. Of course, I played with the fonts and the colors, but just to get the basic arrangement has taken much less than five minutes. But what about the code? It’s also simple as you can see.
The dull boxes are intended for control structures such as event managers and if / then the blocks. The purple boxes are for sub-program calls, and you can define your own sub-programs, although it was not necessary here. Green blocks are properties, such as the URL of the browser. You can Try it yourself If you want.
Rather than transforming this into a complete inventor tutorial, consult one of the incredibly good tutorials on the YouTube channel, like the one below.
https://www.youtube.com/watch?v=ESVTXWPZ6OS
Half of history
Earlier, I mentioned that your friend wanted a robot controller to speak to a Raspberry Pi. I was surprised to see how difficult it turned out to be, but it was not inventor’s fault. There are three obvious choices: the system can make web requests, or it can connect via Bluetooth. It can also work with a serial port.
I made the mistake of deciding to use Bluetooth in series using the Bluetooth customer component. From the inventor’s point of view, it’s easy, if not very sophisticated. But the Linux side turned out to be pain.
There was a time when Bluez, the Bluetooth Linux battery, had a fairly easy way to create a false serial port that spoke of Bluetooth. There are many examples of this internet circulation. But they decided that it was not good for any reason and disconnected it. Modern Linux does not like it all and expects you to create a DBU program that can receive bus messages from the Bluetooth battery.
Be just…
OK, in all honesty, you can recharge the Bluetooth battery with a compatibility flag – at least for the moment – and it will always work older. But you know they will end up deactivating this, so I decided that I should do it the right way. Instead of fighting it, however, I found a code On Github who created a simple customer or server for SPP (the serial port profile). I stripped it to work like a server, then I unrolled a separate function bt_main()
Where you can just write code that works with flows. In this way, all the hocus pocus – and there are many – is out of your way.
You can find my changes to the original code, also on Github. Look at the SPP_BRIDGE.C file, and you will see that these are a lot of disorderly bits to interact with Bluez via DBUS. He records a Profile1
Interface and supply a worker process for each incoming connection. The worker performs the bt_main()
function, which will normally be replaced. The worker reads the Bluetooth socket and writes to your code via a normal FILE *
. You can return data in the same way.
Here is the default bt_main function:
int bt_main(int argc, char *argv[], FILE *in, FILE *out) { // Default demo: echo lines, prefixing with "ECHO: " fprintf(stderr,"[bt_main] Default echo mode.\n"); setvbuf(out,NULL,_IOLBF,0); charbuf[1024]; while(fgets(buf,sizeof(buf),in)){ fprintf(stderr,"[bt_main] RX: %s",buf); fprintf(out,"ECHO: %s",buf); fflush(out); } fprintf(stderr,"[bt_main] Input closed. Exiting.\n"); return0; }Retrospectively, it could have been preferable to simply use the compatibility indicator on the Bluez server to restore the old behavior. At least, as long as it lasts. This implies finding where your system launches the Bluez service (probably in a systemd service, these days) and adding a -C to the command line. There can be a more recent version of RFCOMM which also supports the last Bluez configuration, but KDE Neon did not.
On the other hand, it works. THE
bt_main
The function is easy to write and allows you to focus on solving your problem rather than how to configure and demolish the Bluetooth connection.Next time
Next time, I'll show you a more interesting BT_Main with an Android application that sends and receives data with a personalized server. You can use it as a basis, for example, of a personalized macropad or an Android application to control a robot.