Hub and server deployment on raspberry pi | Communication among hub, server, badges

61 views
Skip to first unread message

Bo Doan

unread,
Apr 1, 2019, 4:46:01 AM4/1/19
to Rhythm Badges

Hi everyone,


I work with Martin Atzmueller in Tilburg University (The Netherlands) in setting up the badges for an experiment. So far I have tried to do the set up (servers and hubs for the badges) on my private network but not made any much of a progress - hubs server badges seem not communicate with each other at all. The 5 badges and a raspberry pi, which I am playing with now, I believe Martin got from Human Dynamics groups. 


What I did is fully deploying the code on the pi. On the pi (both raspbian stretch and hyprios), I cloned openbadge-server and openbadge-hub-py from github and save them inside one directory. Then build and up the .yml in the 02 sub-directories following the instruction on the READMEs (the two .env were set up accordingly). (I tried setting up with docker-machine via ssh from my lap to the pi too - the results are similar).


These are the docker containers I ended up with:

pi@raspberrypi:~ $ docker ps
CONTAINER ID        IMAGE                                         COMMAND                               CREATED                         STATUS                                PORTS                       NAMES
4759b27903c8        openbadgeserver_django            "/bin/bash"                    2 days ago                Up 2 hours                          5000/tcp                 openbadgeserver_django_run_3
b0461a9d1e3f        openbadgehubpy_aws-backup         "./entrypoint.sh"        2 days ago          Up 2 hours                                                            openbadgehubpy_aws-backup_1
6d646debdb65        openbadgehubpy_openbadge-hub-py   "./badge_hub.py -m s…"   2 days ago          Up 2 hours                                               openbadgehubpy_openbadge-hubpy_1
05cb57508401        openbadgeserver_nginx               "nginx -g 'daemon of…"   2 days ago          Up 2 hours                      0.0.0.0:80->80/tcp       openbadgeserver_nginx_1
2333fdcec410         openbadgeserver_django              "/entrypoint.sh /gun…"   2 days ago          Up 2 hours                        5000/tcp                 openbadgeserver_django_1
bd5a5ea88117        openbadgeserver_django            "/entrypoint.sh pyth…"   2 days ago          Up 2 hours                       5000/tcp                 openbadgeserver_django_run_2
0e55bbb23a53        openbadgeserver_django            "/entrypoint.sh pyth…"   2 days ago          Restarting (0) 57 seconds ago                            openbadgeserver_django_run_1
21a971497372        openbadgeserver_postgres          "docker-entrypoint.s…"   2 days ago          Up 2 hours                      5432/tcp                 openbadgeserver_postgres_1
84a5ee1c5c9a        redis:latest                                     "docker-entrypoint.s…"   2 days ago          Up 2 hours                      0.0.0.0:6379->6379/tcp   openbadgeserver_redis_1


From my laptop, I can access to the server on a web-browser, login using the username and password I gave while creating the super user for the django app - everything looks "normal" on the surface I guess. 


But even though the Bluetooth of the pi and the badges are working - the pi can detect and connect to the badges, when I create a project with 02 badges (their MAC addresses were filled under "badges", the container ID of openbadge-hub-py was filled under the "hubs" as I assume it is the hub hostname): 


1.png

2.png


..they does not communicate:

pi-dashboard.png

I can seem to work out the problems (must I deploy the hubs and servers on separated hosts?, etc...). I am also not familiar with the network structures among docker containers. Would anyone have any suggestions? 


- Thank you in advance.

Bo

Oren Lederman

unread,
Apr 1, 2019, 8:24:31 AM4/1/19
to Bo Doan, Rhythm Badges
Hi Bo, I'll be happy to help, but later this week (I'm defending my PhD today. ). 

To make things easier for me, and to help others who might face similar issues, could you please post the question in our forum?


There might already be an answer to your question there (might need some digging)

Oten

--
You received this message because you are subscribed to the Google Groups "Rhythm Badges" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rhythm-badge...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rhythm-badges/52bc1c4e-4ffb-484e-b810-46cd17ef3203%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bo Doan

unread,
Apr 1, 2019, 5:27:52 PM4/1/19
to Rhythm Badges
Hi,
I think it is already on the forum.
And best of luck with your defense today. 
Have a really nice day!
Bo

Oren Lederman

unread,
Apr 2, 2019, 6:37:58 PM4/2/19
to Rhythm Badges
Sorry for that - I got confused because I am getting updates to my mailbox as well :)

A couple of things:
  • Please use uppercase when you enter the MAC addresses. Not sure if lowercase would work (never tested it). Shouldn't cause what you are describing here
  • You need to put something the the ALLOWED_HOSTS in the server's env file. A good thing to try if you can't get the hub and server to talk is a wildcard - * (just star) . Not great for security, but also very low risk. Try that, and see if anything changes
  • Make sure the APP_KEY is the same in both .env files
If you like, you can post your env files here and i'll take a look. 

Also, have a look at the hub log. You can do it by using docker-machine to set it as the active machine, and then run "docker-compose logs" to get the logs (you'll need to be in the openbadge-hub-py folder when you do that).

Bo Doan

unread,
Apr 3, 2019, 8:53:08 AM4/3/19
to Rhythm Badges
Hi,

I'll try to update the MAC address to uppercase. 

For now, this is the error return from terminal attach to the container of the hub:
pi@raspberrypi:~ $ docker attach 6d646debdb65
2019-04-03 04:41:49,340 - INFO - Requesting devices from server...
2019-04-03 04:41:49,373 - ERROR - Error reading badges list from server : HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /badges/ (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x764f8a10>: Failed to establish a new connection: [Errno 111] Connection refused',)), Traceback (most recent call last):
  File "/app/badge_manager_server.py", line 45, in _read_badges_list_from_server
    response = requests.get(BADGES_ENDPOINT, headers=request_headers(), timeout=self.DEFAULT_TIMEOUT)
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 70, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 487, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /badges/ (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x764f8a10>: Failed to establish a new connection: [Errno 111] Connection refused',))

This is the .env in the hub directory:
BADGE_SERVER_ADDR=raspberrypi
BADGE_SERVER_PORT=2376
APPKEY=uvtDesignFuture
AWS_ACCESS_KEY_ID=NONE
AWS_SECRET_ACCESS_KEY=NONE
AWS_S3_BUCKET_URL=NONE
AWS_DEFAULT_REGION='eu-central-1'
CRON_SCHEDULE=0 0 * * *
TZ=Europe/Amsterdam

This is the .env in the server directory:
# Django settings
DJANGO_SECRET_KEY="BETot40xUS!itHEsAjUS"
ALLOWED_HOSTS=*

# Postgres settings
POSTGRES_DB=openbadge
POSTGRES_USER=openbadge
POSTGRES_PASSWORD=password

# Badge server settings
APP_KEY=uvtDesignFuture
GOD_KEY=dummy

Maybe some problems with the set-up of the BADGE_SERVER_ADDR and BADGE_SERVER_PORT? I'm not sure how to look at the hub log too.

Regards,
Bo

Oren Lederman

unread,
Apr 3, 2019, 9:40:59 AM4/3/19
to Bo Doan, Rhythm Badges
The values you have in the .env file for BADGE_SERVER_ADDR and BADGE_SERVER_PORT dont match want you show me from the log file. The log file shows localhost on port 8000.

A a couple of thoughts:
* Are you running the server in Dev or production mode? If you are running it in production mode, the port should be 80, not 8000. Host address is "localhost" if you are running both hub and server code on the same pi
* Check the name you gave the hub in the project settings. The screenshot you showed me had a very long string there, not sure what's the origin. It should be the hostname of the rapsberry pi running the hub. If it's wrong, it won't work

Can you try these two, and let me know? Base in the error you got, I think the current problem is the host and port.

I do have to say that I haven't tried running the server code on a rapsberry pi, and I haven't tried running the server code and hub code on the same machine. Might cause some issues I can't think of at the moment.


--
You received this message because you are subscribed to the Google Groups "Rhythm Badges" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rhythm-badge...@googlegroups.com.

Bo Doan

unread,
Apr 3, 2019, 10:22:28 AM4/3/19
to Rhythm Badges
Ahhh.. I see. I'll try this by the end of this week and let you know. 

Meanwhile, we have just tried run in standalone mode and everything looks fine: there are data file appears under data directory and some data are recorded.

To unsubscribe from this group and stop receiving emails from it, send an email to rhythm...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages