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

5 Likes
#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?

1 Like
#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.

2 Likes
#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 Likes
#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.

1 Like
#6

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

1 Like
#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

4 Likes
#8

Hi,

I have just updated the GitHub page for Mesh Toolkit with an example script using the Python SDK to provide an “On the go” client “goTennaHub” for goTenna here.

The client works by providing a web server running on the host device which allows users to connect to the host via a browser and then send messages over the goTenna network to other devices running “goTennaHub” without the need for installing a device specific client.

An example of how this could be used would be to have a few “goTennaHubs” located around a campsite, which does not have 4g, using cheap travel routers like the ar300m, to provide ad-hoc messaging.

Access to the Hubs could be provided using QR Codes - one to connect to the router and the second to open the Web App - To connect you simply scan the two QR Codes. An example of a online QR Code generator is here.

This approach means that you don’t have to share passwords with the users.

To use the goTennaHub install python and the SDK then run the script:

python gotennaHub.py

Note: it is assumed that the script is run from the folder ‘/gotenna/‘.

You will also need an SDK Key from goTenna.

You can then connect from a browser on the same network:

http://<rooter ip address>:8080

Then you will get a screen similar to:

22

When you send a message it will be routed over the goTenna mesh to other devices running the goTenna hub, it will also appear on any other devices connected to the same router.

Messages will update after a few seconds (the check is every seconds).

On the ar300m, you can automate the startup by editing the file “/etc/rc.local” and adding the line:

/gotenna/gotennaHub.py > /var/log/gotenna.log 2> /var/log/gotenna_error.log &

When the router is powered on it will then automatically connect to the goTenna - but be give it a few minutes…

Yo can also automate timestamp messages by adding the following line to the “crontab” file:

*/5 * * * * curl 'http://localhost:8080/timestamp'

This will send a message every five minutes - although if the router is not connected to the internet the timestamp will be wrong as the router does not have a real time clock.

You can also send messages from other scripts etc, by simply percent encoding the messages and doing a curl request - e.g.:

http://<rooter ip address>:8080/Message%20goes%20here

The code is still basic - it does not have much error handling and should really use a queue to ensure messages are not lost without breaking the 5 messages per minute limit.

Due to the nature of the router when you power it off it does not close the connection to the goTenna down correctly and you must cycle the power on the goTenna before restarting the router.

Hope this all makes sense…

4 Likes
#9

This is all very cool and thank you for sharing all the work you’re doing!

Some questions, can a goTennaHub send messages to a standard goTenna user (goTenna + phone), or is it strictly goTennaHub to goTennaHub? Shouts and group messages supported?

Thanks!

2 Likes
#10

Hi Sierra,
Thank you for your comments.

In answer to your questions:

GoTennaHub cannot send or receive messages from the goTenna App.

The SDK does not allow messages to be exchanged with applications using a different SDK Key or the standard app.

This is both for security and also to protect the available bandwidth - there is a good explanation for this in the goTennaSDKintro.pdf included with the SDK.

In its current form, goTennaHub only supports shouts, although there is no technical reason why it cannot be extend to support one to one messaging.

I have just pushed a new version of goTennaHub to GitHub, which cleans up a couple of issues with the code and also includes battery and temperature info as part of the “timestamp” functionality.

This would allow you to use goTennaHub in a different scenario, where you have a number of GoTenna’s in fixed locations acting as repeaters.

Adding ar300m’s running goTennaHub and a cron based timestamp would allow for the devices to keep track of battery levels etc and also communication drop outs as all of the devices would be talking to each other.

If you were to do this, I would suggest that you change line:

if len(messagesArray) > 100:

To a different value as this limits the number of messages recorded to 100.

Crucially, though the devices would still be acting as beacons as my understanding is that even though you are using a specific SDK token, the goTennas will still route other messages over the mesh.

To monitor your mesh you would simply have to connect a device with a browser to one of the routers.

Hope this helps.

2 Likes
#11

Hi Pete94,

Thanks for the explanation and thanks again for sharing your work. Once I get the hardware, I’ll start doing some tests.

1 Like
#12

One option you might want to try is building up a version of the Signal App that I modified to add goTenna support. You can use your own SDK Token and it then should be able to exchange messages with goTennaHub.

There are other open source messaging apps like Manyverse that are meant to be used offgrid that also should be pretty easy to modify to add goTenna Mesh support.

2 Likes
#13

I’m planning to work on a similar project (when I get my SDK key). Where goTenna (from the gT App) shouts gets posted as a feed on a webpage. Would this be possible?

1 Like
#14

Unfortunately the App ID for your python project will be different than the gT App and it won’t be able to receive messages from the gT App. Unless there’s something special with the gT App I’m not aware of.

1 Like
#15

Hi,
Rmyers is correct, the messages sent from the API are only accessible from other Apps/SDK scripts running the same token - see GoTenna Python SDK above.

It would be great if the GoTenna App allowed for messages to be handled both from the default token and also a user defined SDK token to allow for teejz’s type of application.

This would allow for user’s to work on their own “sub mesh” using the standard GoTenna App able to interact with the SDK, although I can understand that there are most probably good technical reasons why this might be hard to implement.

I think it would need new firmware for starters as the lights on the GoTenna linked to the SDK don’t flash when a message is broadcast from the App…

Setup could implemented using a URL schema, which would allow a user to scan a QR Code using the standard Camera App or sent via email, to quickly setup the secondary Token.

1 Like
#16

@rmyers - Aha, so messages from the gT app isn’t able to publish messages (even Shouts) to other apps? Thanks for the heads up.

1 Like
#17

@pete94, that would be great if the GoTenna app messages can be handled by 3rd party applications. We have a small but geeky GoTenna outdoor-savvy userbase where I am now (Philippines), and would love to use GoTenna for broadcasting at least Shouts that can be parsed by a Python script to a webpage. Much like a message board / feed.

@danielagotenna, would this be in the pipeline with GoTenna SDK soon? And I’ve yet to receive my SDK token. :upside_down_face:

1 Like
#18

@derek_gotenna @MikeR Adding our product managers here to reply! :slight_smile:

1 Like
#19

@danielagotenna that’s great ~ a big :heart: out to you guys! Thanks! And Nate already got me setup with a token. And burning the midnight oil on the first test app. :slight_smile:

#20

Hi @teejz!
@rmyers has done a great job keeping up here and helping explain the reasons why the goTenna app doesn’t communicate with 3rd party apps.

When it comes to broadcasting- I don’t see a reason not to allow broadcast communication between apps. I just can’t answer if that’s technically possible. We can talk with our app and SDK teams and once we understand all of the details, can consider offering this.

Keep us posted on your progress, or if you have more questions! Tag me in your posts- I’m happy to help :smiley:

2 Likes