GoTenna Python SDK


#1

Hi,
I have been experimenting with what is the minimum hardware to get the Python SDK working, and with the following:

Have done the following:

Example video

The total hardware needed comprises a Raspberry PI Zero-W and a Micro to Micro OTG USB cable.

Still a few bugs in my code, but implementation of the GoTenna SDK was straight forward.

Seasons greetings.

Pete


#2

What have you been able to accomplish with this connection thus far? (outside of the video) Would you consider doing a write-up of how you got to this point?


#3

@Pete94 thanks for sharing! Glad to hear you found the SDK implementation to be straight forward. Let us know if you have any questions.


#4

Hi,
A quick update on progress, I have moved on from using a Raspberry Pi as the Python host to:

Although still work in progress and apologies for the poor picture, but its a shiny black box…

The device is a travel router running OpenWRT ar300m.

The main reason for choosing the Router over the Pi is that it already provides a hotspot and an ethernet connection in a smaller form factor. The nature of the device means that it is effectively headless once configured.

I am building a simple web application which is able to send messages to GoTennas from a browser running devices connected to the router (using web sockets), along the lines of Side-loaded or offline version of app.

Installing the Python SDK on OpenWRT was straightforward, although some of the prerequisites have different package names and I had to make a small change to one of the SDK libraries to handle the lack of a SPI interface.

It is also interesting to be working with a device with limited resources (although I played safe and went for the ar300m with 128mb of Flash storage - I think I could of got away with a GL-MT300N which only has 16mb of Flash and is less than £20).

The OpenWRT approach also opens up the hardware that can be used as the host, as it can be flashed to a wide range of routers…

I will do a more detailed write up once I have cleaned up the code :slightly_smiling_face:


#5

What a great idea!

I would love to try it out on a GL-AR150 I have laying around once you’ve written up what you did to get the SDK running on the ar300m.


#6

Please do the write-up. I managed to get an ar300m for $17.99 from Amazon Prime.


#7

Hi rmyers and aspexin,
Below are the basic steps for getting the SDK working on the ar300m, but I would think that the steps would generally apply for other OpenWRT devices.

The one caveat is the amount of storage the device has - I went for the ar300m with 128mb of storage to ensure that I had enough headroom for installing the dependencies.

I would think that you could install it on a device with 16mb of storage but you might have to remove some packages not needed (possibly python-base rather than python-light?).

I also stuck with the stock firmware although you might be able to get some more space with vanilla OpenWRT.

I tried the deployment on an X86 version of OpenWRT running under VirtualBox before installing on the ar300m - This just meant that when I got something wrong I could go back to a snapshot so I knew that I was on a clean build.

I also did the git clone onto my laptop rather than copy the full GoTenna repository to the router.

The actual steps of installing the SDK follow closely the GoTenna instructions (apologies if I have missed anything - when I have time I will reset the device and run through the steps to check).

You will also need internet access for the router during the setup stage - either by cable or WISP mode, SSH also needs to be enabled (its was on by default on my device).

I also found that I had to connect the laptop to the router.

The basic process is:

1 - Update the package manager (this needs to be done every time the device is rebooted):

opkg update

2 - Then I installed python 2.7 and went for the “python-light” package (https://openwrt.org/docs/guide-user/services/python), you might get away with python-base but I would expect that you need to install some other python packages:

opkg install python-light

3 - You then need to install the python package manager (pip):

opkg install python-pip

4 - Then you need to install cffi and cryptography support, the packages are different to the GoTenna documentation:

opkg install python-cffi
opkg install python-cryptography 

5 - I found that I was getting an “out of memory error” when I initially tried to install the GoTenna SDK, to solve this I found that upgrading pip resolved the problem (even though I had just installed it…):

pip install --upgrade pip

6 - Make a working directory on the router:

mkdir /gotenna/
cd /gotenna/

7 - On a laptop get the GoTenna SDK from gitlab, then copy the install file to the router:

scp goTenna-0.12.5-py2-none-any.whl root@192.168.x.x:/gotenna/

8 - You can install the GoTenna SDK:

pip install goTenna-0.12.5-py2-none-any.whl

9 - To test the installation works, launch python:

python
import goTenna

It will either work by simply returning to the prompt or throw an error about a failure to import the “spi” library (it takes a few seconds to load).

10 - I could not find a suitable package and the router does not appear to have an spi interface, so I edited the following file:

/usr/lib/python2.7/site-packages/goTenna/spi_connection.py

I changed the string “Linux” on line 34 (I think but check the line number in the error message), to “Linux-Disabled” and this stopped the SDK attempting to load the library.

11 - You can then copy the “sample.py” script to the router and if you have a valid API Key it should all work…

Hope this makes sense and works for you…

Pete