Skip to content

Code behind parts of the Nottinghack instrumentation project, including the MQTT IRC bot nh-holly & server side parts of GateKeeper

Notifications You must be signed in to change notification settings

NottingHack/instrumentation

Repository files navigation

Contents
========
This repository contains various parts of the Nottinghack instrumentation project. This includes (server side parts only, where applicable):
* GateKeeper (GateKeeper.cpp), See http://wiki.nottinghack.org.uk/wiki/Gatekeeper

* Vending machine (nh-vend.cpp). See http://wiki.nottinghack.org.uk/wiki/Vending_Machine/Cashless_Device_Implementation

* Studio/comfy area LED display (nh-matrix). See https://github.com/NottingHack/LED-Matrix-board for firmware, and http://wiki.nottinghack.org.uk/wiki/LED_Matrix for more details.

* IRC bot, nh-holly, resident in #nottinghack on Freenode (nh-irc.cpp). See http://wiki.nottinghack.org.uk/wiki/Nh-holly

* Blue room LED display (nh-mini-matrix.cpp). See http://wiki.nottinghack.org.uk/wiki/Mini-matrix

* Temperature monitoring (nh-temperature.cpp). Cacti is used to graph the data, see https://github.com/NottingHack/Cacti-Scripts/ for the sctipts, or http://cacti.nottinghack.org.uk/graph_view.php for live graphs. The blue room, comfy area & studio sensors are connected to the LED matrix display (and directly reports to nh-temperature), the fridge temperature sensor is connecting to the blue room LED display, and reports the temperature to nh-temperature via nh-mini-matrix (UDP connection from the display to holly).

* Google group monitoring (nh-mail.cpp)
Fetchmail is configured to check holly's email account (which is subscribed to the Google group), and invoke nh-mail for every email received. This this then publishes the topic of the emails to MQTT, which is displayed on the two LED displays. 

* irccat (nh-irccat.cpp)
Allows some of the simpler IRC scripts stolen from London Hackspace (https://github.com/londonhackspace/irccat-commands) in the irccat/ directory to run.

Web stuff (web/ directory)
==========================
There is some miscellaneous web/php stuff in here:
* Auth.php - Wiki authentication plugin. This part is installed on the main Nottinghack web server, and talks to wikiauth.php on holly. Used to allow HMS logins to be used on the Wiki (wiki account gets auto-created on first login). 

* krb5_auth.php - Kerberos authentication - used by nh-web and the Wiki plugin

* vend.php - Show what's currently in the vending machine. Currently at http://lspace.nottinghack.org.uk/vend.php

* wikiauth.php - Authenticate wiki users using HMS username/passwords. This part runs on Holly, and is accessed by Auth.php on the Wiki server

* status/ - Implementation of SpaceAPI (http://hackerspaces.nl/spaceapi/), see http://hackerspaces.me/

Database creation
=================
The database structure should match current "Release" version of HMS (https://github.com/NottingHack/hms), as the two projects share the same database on Holly (but access it using different usernames). An existing HMS-only database (e.g. one created by the HMS dev/setup script) can also be used by skipping the steps where noted.

1) Create a database, and user account with select only permissions
   on all tables in the database, e.g. from the MySQL shell as an admin user:
       mysql> create database <new db name>;  -- (skip if using a pre-existing HMS database)
       mysql> grant select on <new db name>.* to '<new db user>'@'localhost' identified by '<new password>';
       mysql> flush privileges;
 
  2) Set the database/username/password in:
      conf/default.conf - used by C++ processes. This should be the account created in step 1)
      db/database.conf  - used by db_load.php and the stored procedures when loaded. Needs two accounts setting: 
		'mysql_runtime' - the account created in step 1)
        'mysql_admin'   - an account with sufficent priviledges to drop/create tables, select, insert, delete and update anything in the new database.
  
  3) If starting with an empty database, change to db/, then run "php db_load.php ALL", this will create the necessary tables and stored procedures. If using an existing HMS-only database, run "php db_load.php", and answer "yes" to loading all SPs. 
     To reload a single SP (e.g. after a change), specify the filename on the command line instead of "ALL".
  
  4) Create an example user. E.g. from the MySQL shell:
   mysql> call sp_add_member(1, 'test member', 'test handle', 'welcome test', '1234', '[email protected]', sysdate(), 'testusername', @err, @memberid);
  
The database should now be set up, with relevant static data loaded.

Building
========
Along with the usual build tools (GCC, etc), Mosquitto & development libraries are also required. On Debian GNU/Linux, these can be installed by running:

wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key  
sudo apt-key add mosquitto-repo.gpg.key  
cd /etc/apt/sources.list.d/  
sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.list  
sudo apt-get update 
sudo apt-get install libmosquitto1 libmosquitto1-dev mosquitto mosquitto-clients

To build all processes in the project, run "make all" in the project root, this should build everything (tested on Debian Squeeze & Wheezy).

Config & Testing
================
* IRC bot
  1) Set the IRC server, channel & nick & logfile in conf/nh-irc.conf
  2) Run "./nh-irc -d -c conf/nh-irc.conf". -d indicates debug mode - i.e. don't daemonise, and output all logging info to the terminal, not the logfile.
Assuming it managed to connect to IRC and Mosquitto/MQTT, a test message can be sent to the IRC channel by running:
# mosquitto_pub -t nh/irc/tx -m "Hello, World\!"

* Everything else: TODO. But much the same.




About

Code behind parts of the Nottinghack instrumentation project, including the MQTT IRC bot nh-holly & server side parts of GateKeeper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published