Basic Starter I/O Code

Started by CastleWorks, January 13, 2015, 02:51:09 AM

Previous topic - Next topic

CastleWorks

Hi All,
I am brand new to the forum and purchased an A13-OlinuXino-WIFI board.
I would like to develop an android app for controlling the board I/O
Is there a basic boiler plate code that I can start with? I am looking for something I can both read and write to I/O ports.
Thanks!
Castle Works


CastleWorks

Thanks for the reply and information, this looks promising!

dave-at-axon

I am busy updating my blog to show how to build the JNI to do this but in the meantime if you are willing to look up Android NDK and install it yourself, you can download these files to give you a JNI and JAVA code to do I2C and GPIO on the A20, A13 etc under Android. You need the NDK to compile it. Just use the batch files to build the JNI but edit them to change the directory structure. What the naming convention as it uses Python so path names are no the same as DOS. If you are a Linux man, you'll need to convert the bat files to .sh and make changes as needed.

The code on the link from Olimex is actually mine which someone has found and used :)

The version below has been updated to resolve some issues with function names.

http://www.axoninstruments.biz/download/gpio/gpio-JavaSource.zip

http://www.axoninstruments.biz/download/gpio/GPIO-JNI.zip

http://www.axoninstruments.biz/download/gpio/sample.zip

This will eventually go up on Github but for now you can download from above.

CastleWorks

HI Dave,

Thanks for the links and files, they will be very helpful.

Let me ask a similar question to the forum, is there similar basic building block code available to control the I/O from a smartphone over wifi?  My ultimate goal is to create a mobile app that can link to my A13 connected to my home wireless network while away from home.

I appreciate any input and guidance from those that have don similar projects.

Thanks

dave-at-axon

If you have Android on both, check out Google Cloud Messaging. See if you can find the sample Google did with 2 count down timers in sync over GCM.

GCM avoids you needing any IP addresses.

CastleWorks

If I chose not to go the route of GCM, is anyone aware of examples of an adroid app using IP addresses for connecting to the A13 via the mobile app?

Thanks

dave-at-axon

You an do IP to IP as easily as any other socket programming but the issue you have is knowing what the IP address of the end device is and if you are on the same subnet.

If you want to do this within your own network and subnet, you can have your server device listening for UDP data on a port, say 5000. You other device will when it starts, try to connect to the IP address is last knew about and if that does not connect, you then send a UDP broadcast on .255 on port 5000 and your server device will see this, confirm the data in the packet is correct (username, password etc) and then send back a reply via TCP/IP to the IP address it detected the UDP data from. You now have the IP of the server and the server has the IP of the device (for as long as it is present and the IP not changed) You have to consider that more than 1 device may have the same IP at some point because of DHCP so your protocol has to handle this with a user ID and or password.

If you are wanting to do this from outside your network then that gets  more complicated and you will either need a fixed IP address or use something like DYNDNS to handle this for you. You also need to open ports on your router and setup re-direction.

To be honest, going the GCM route removes all of this and makes it easy to do but at the cost of needing a server (website with PHP will work) to handle the GCM messages back and forth.

CastleWorks

Dave,
Thanks for the input on this...it made me think I probably need to set out some requirements for my project.

1. I need to connect to this device from outside my network.
2. Using GCM is really not an option due to the requirement of a server.
3. I am alreday usinng DynDNS for other commercial apps (security system etc), so a changing IP address is not a concern for me at this point.

All that said I am really looking for boiler plate code for where I can connect to my A13  remotely (with password protection) knowing my IP address. Once conencted I would like to read and write to the A13 I/O channels and (thinking longer term) ultmately view video from a USB camera connected to the A13.

I realize this is quite a lot to take on initially but with all the commercially avaiable products out there doing this already (security cameras, garage door operners, thermostats etc) I am hopeful some basic boiler plate code exists for these type of tasks.

Any building blocks of code would be appreciated. I am a rookie to android programming and even basic socket programming, so I welcome any suggestions or opinions.

Thanks
CastleWorks