Atmosphere API
1.3K
Measurify is a cloud-based, abstract, measurement-oriented Framework for managing smart things in IoT ecosystems. More information about the framework are published at this link measurify.org. This is the code base of the Measurify Server module implementing a RESTful API exposing Measurify resources.
Measurify Cloud API Server is designed, developed and maintained by Elios Lab of University of Genoa. Wondertech contributes to the development and maintenance of the source code.
In order to support the IoT developer community, Measeurify Cloud API Server is released open source under MIT licence.
Clone code and run the container
git clone https://github.com/measurify/server.git
docker-compose up
The Measurify Cloud API Server is developed using Node JS and MongoDB. The following steps show how to deploy a complete enviroment on a Ubuntu 16.04 server, however it can be adapted also for MacOS or Windows operating systems.
Detailed information can be found at MongoDB Community Edition Installation Tutorials
system sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo service mongod start
tail /var/log/mongodb/mongod.log
Check for "[initandlisten] waiting for connections on port 27017"
sudo service mongod stop
sudo service mongod restart
sudo systemctl enable mongod.service NodeJS
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get dist-upgrade
sudo apt-get install rcconf
sudo apt-get install build-essential
sudo apt-get install libssl-dev
sudo apt-get install git-core
sudo apt-get install python2.7 type python3 python2.7 python3.5 python2 python
Remember the URL of the database server, if you are using the same machine for MongoDB and NodeJS, it will be "localhost"
Detailed information can be found at NodeJS installation
sudo wget http://nodejs.org/dist/v8.11.1/node-v8.11.1.tar.gz
sudo tar xzf node-v8.11.1.tar.gz cd node-v8.11.1/
sudo ./configure --prefix=/usr
sudo make
sudo make install
cd ~ git clone git://github.com/isaacs/npm.git
cd npm/scripts
chmod +x install.sh
sudo ./install.sh
sudo npm install connect redis connect-redis jade express express-resource futures emailjs socket.io http-proxy
sudo npm audit fix
cd ~
mkdir ~/www
cd ~/www
cd ~
sudo npm install -g forever
cd ~/www
sudo git clone https://github.com/measurify/server.git
cd api/
sudo npm install
npm run-script prod
Measurify Server can run in tree different modes: "prod" (to start in production), "dev" (to run the code using the nodemon tool) and "test" (to execute the unit test suite). It is possible to select the enviroment using a command line parameter:
npm run test
npm run dev
npm run prod
Each environment has a configuration file "variable.dev.env", "variables.prod.env", "variables.test.env" which can be edited in order to specify several features:
VERSION=v1
ENV=development
DATABASE=mongodb://localhost:27017/measurify-dev
PORT=8084
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin
JWTSECRET=secret-dev
HTTPSSECRET=measurifyPass
EXPIRATIONTIME=30m
LOG=enabled
In particular, the connection string with the database and administrator credential (at startup Measurify Server will create a admin user with these credential), the expiration time of tokens, the log level, the secret word for the HTTPS certificate file and the secret word for the JWT token.
We suggest to use a process manager for NodeJS, like pm2
sudo npm install -g pm2
sudo pm2 start api.js -- prod
sudo pm2 show api
sudo pm2 save
sudo pm2 startup
curl localhost
curl localhost 8084
Measurify Server can support both HTTP and HTTPS. Without certificate, the API starts using a self-signed certificate (stored in the resources forlder) or in HTTP (if also the self-signed certificate is missing). It is reccomended to get a valid certificate from a authority. In the following, we provide instruction to add a certificate from Let's Encript, a free, automated and open Certificate Authority. Detailed instruction can be found at Certbot instruction
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot
sudo ufw allow 80
sudo certbot certonly --standalone --preferred-challenges http -d *.measurify.org
sudo cp /etc/letsencrypt/live/measurify.org/fullchain.pem ~/www/api/resources/fullchain.pem
sudo cp /etc/letsencrypt/live/measurify.org/privkey.pem ~/www/api/resources/privkey.pem
sudo pm2 stop api
sudo pm2 start api
It should run on HTTPS: sudo netstat -tulpn
Content type
Image
Digest
Size
440.6 MB
Last updated
over 5 years ago
docker pull atmosphereframework/atmosphere-api