”2016-10-03”

This commit is contained in:
Martin Donnelly 2016-10-03 16:45:02 +01:00
parent f3dba8b6f0
commit 5b0bf4e9f7
5 changed files with 261 additions and 7 deletions

View File

@ -1,4 +1,38 @@
# MQTT Archiver
# mqttArchiver
This app listens to all the available subscriptions for a given MQTT server then archives the raw data in a PGSQL database.
> MQTT Listener and archiver
background details relevant to understanding what this module does
## Usage
To run in development mode run:
```bash
pm2 start app.js
```
or
```bash
npm start
```
To run in production mode:
```
npm run production
```
mqttArchiver was inspired by..
## See Also
- [`noffle/common-readme`](https://github.com/noffle/common-readme)
- ...
## License
ISC

View File

@ -16,7 +16,7 @@ var db = require('./lib/server/db-connector').dbConnection;
var app = express();
var port = (process.env.VCAP_APP_PORT || 3000);
var port = (process.env.VCAP_APP_PORT || 3100);
var host = (process.env.VCAP_APP_HOST || 'localhost');
var isProduction = false;
@ -163,7 +163,7 @@ var MQTTHandler = function() {
events.emit('saveData', json);
});
this.client.subscribe(mqttAccount.subscribeTopic);
this.client.subscribe(config.mqttAccount.subscribeTopic);
};
var mqttlient = new MQTTHandler();

View File

@ -12,11 +12,11 @@ module.exports = {
appKey: '9txJEf3Cjy7hkSOvkv',
subscribeTopic: 'iot-2/type/+/id/+/evt/+/fmt/json'
}, pgConnection: {
host: 'localhost',
host: 'censis.cew5a5td5ukl.eu-west-1.rds.amazonaws.com',
port: 5432,
database: 'mqttstore',
user: 'postgres',
password: ''
user: 'censis_Lm5zt9BYD',
password: '1bR9nJoC5cFRcO84lu5mzmA7MeKyRW'
}, keypair: {
accessKey: '59079A75F7FBA5B8DD19076D18CE87A7',
secret: '7C7320FEE40BE5CC5E1955354045B6C7A701FF1F64568AE6B3BA3E6D7DB42D6F'

View File

@ -0,0 +1,121 @@
#!/bin/bash
GIT_SERVER="https://censis.visualstudio.com/DefaultCollection/SmartOffice/_git/simpleMQTT"
NVM="$HOME/.nvm"
NVM_VERSION="6.6.0"
DEV="$HOME/dev"
LIVE="$HOME/live"
STAGING="$HOME/staging"
SERVER="simpleMQTT"
NGINXFILE='mdot';
PKG_MANAGER=$( command -v yum || command -v apt-get ) || echo "Neither yum nor apt-get found"
PKG_DEVICE=$(basename $PKG_MANAGER)
pidof systemd && SYSTEMDCALL=1 || SYSTEMDCALL=0
UPDATE=no
DATABASE=no
NGINX=no
INSTALL=no
RED=`tput setaf 1`
GREEN=`tput setaf 2`
YELLOW=`tput setaf 3`
PURPLE=`tput setaf 5`
RESET=`tput sgr0`
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\n$fmt\n" "$@"
}
for i in "$@"
do
case $i in
-us|--updatesystem)
UPDATESYSTEM=YES
shift # past argument=value
;;
-u|--update)
UPDATE=YES
shift # past argument=value
;;
-d|--database)
DATABASE=YES
shift # past argument=value
;;
-n|--nginx)
NGINX=YES
shift # past argument=value
;;
-i|--install)
UPDATESYSTEM=YES
UPDATE=YES
NGINX=YES
#DATABASE=NO
INSTALL=YES
shift # past argument=value
;;
--default)
DEFAULT=YES
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
fancy_echo "${YELLOW}Installing mDot Console Server ...${RESET}"
## Update initial packages
read -s -p "Enter Password for sudo: " sudoPW
fancy_echo "${RED}Cleaning...${RESET}"
if [ ! -d "$DEV" ]; then
mkdir -p $DEV
fi
if [ ! -d "$LIVE" ]; then
mkdir -p $LIVE/$SERVER
fi
if [ ! -d "$STAGING" ]; then
rm -rf $STAGING
fi
mkdir -p $STAGING/$SERVER
# get source and build
# Install global packages.
cd $DEV
if [[ $UPDATE = "YES" ]]; then
fancy_echo "${PURPLE}Updating code...${RESET}"
# Get latest version of Back End
if [ ! -d "$DEV/$SERVER/.git" ]; then
git clone $GIT_SERVER
else
cd $DEV/$SERVER
git pull origin master
fi
# Rebuild backend end
cd $DEV/$SERVER
rsync -uav -q --exclude .git $DEV/$SERVER/ $STAGING/$SERVER
cd $STAGING/$SERVER
npm install . && npm-install-missing
# Update live versions
fancy_echo "${YELLOW}Copying files to LIVE...${RESET}"
rsync -uav --delete-delay -q --exclude .git $STAGING/$SERVER/ $LIVE/$SERVER
fi

View File

@ -0,0 +1,99 @@
-- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
-- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
-- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
-- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
-- WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
-- YOU ***MUST*** change 'vmlcokon' to the name of the database user before running this script on a new database.
--
-- Name: insert_raw(timestamp with time zone, character varying, character varying, character varying, json); Type: FUNCTION; Schema: public; Owner: vmlcokon
--
CREATE FUNCTION insert_raw(_timestamp timestamp with time zone, _type character varying, _device character varying, _event character varying, _data json) RETURNS void
LANGUAGE plpgsql
AS $$
BEGIN
INSERT into raw("timestamp", type, device, event, data) Values(_timestamp, _type, _device, _event, _data);
END;
$$;
ALTER FUNCTION public.insert_raw(_timestamp timestamp with time zone, _type character varying, _device character varying, _event character varying, _data json) OWNER TO vmlcokon;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: raw; Type: TABLE; Schema: public; Owner: vmlcokon
--
CREATE TABLE raw (
id bigint NOT NULL,
"timestamp" timestamp with time zone,
type character varying(24),
device character varying(24),
event character varying(24),
data json
);
ALTER TABLE raw OWNER TO vmlcokon;
--
-- Name: raw_id_seq; Type: SEQUENCE; Schema: public; Owner: vmlcokon
--
CREATE SEQUENCE raw_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE raw_id_seq OWNER TO vmlcokon;
--
-- Name: raw_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: vmlcokon
--
ALTER SEQUENCE raw_id_seq OWNED BY raw.id;
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: vmlcokon
--
ALTER TABLE ONLY raw ALTER COLUMN id SET DEFAULT nextval('raw_id_seq'::regclass);
--
-- Name: raw_device; Type: INDEX; Schema: public; Owner: vmlcokon
--
CREATE INDEX raw_device ON raw USING btree (device);
--
-- Name: raw_lower_idx; Type: INDEX; Schema: public; Owner: vmlcokon
--
CREATE INDEX raw_lower_idx ON raw USING btree (lower((type)::text));
--
-- Name: raw_lower_idx1; Type: INDEX; Schema: public; Owner: vmlcokon
--
CREATE INDEX raw_lower_idx1 ON raw USING btree (lower((device)::text));
--
-- Name: raw_type; Type: INDEX; Schema: public; Owner: vmlcokon
--
CREATE INDEX raw_type ON raw USING btree (type);