1. Home
  2. Docs
  3. User Guides
  4. Avimesa Sails

Avimesa Sails

Pre-requisites for this installation:

  • Node.js v8 or higher
  • Sails v1.0 framework

If you’re not sure of the version of Node.js, open a terminal window and type node -v

If it’s v8 or greater, you’re good to go. Else click here to install or upgrade.

Next, we need to install Sails.js globally. To do that, type the following command in your terminal:

npm install sails -g

If you receive an error or you’re on OS X run the following command:

sudo npm install sails -g

It may take a minute to install.

To get started developing locally, clone this project and cd into its top-level folder.

Before running the project locally for the first time, run:

npm install

You’ll need to configure your app with your Avimesa credentials. In your app’s config/custom.js file, fill in avimesaApiKey with your API key, and avimesaApiPassword with your API password. You can also configure items under Display names/dates for your app to automatically replace all instances of NEW_APP_NAME, etc with your own brand and dates.

Don’t have Avimesa credentials yet? Click here.

If you have an Avimesa test device and would like to seed your app with some example sensor data, you’ll also want to fill in avimesaTestDeviceId with the ID of your test device.

The test device data will be automatically configured with sensors on channels 1 and 2. If the sensors on your Avimesa 1000 are configured elsewhere, you’ll want to leave this out and manually add your sensors from the dashboard.

Be sure to also update items under Display names/dates for your app in config/custom.js to automatically update.

Now that you’ve configured your app, you’re ready to start the server for local development. Just run:

sails lift

If you see a sailboat, congratulations! Your app should now be available on http://localhost:1337.

Troubleshooting tips
  • If you see “command not found”, run npm install -g sails to install the Sails command line tool.
  • If you see “EACCES” or “permission denied” when installing the Sails command-line tool on a *nix operating system, try doing sudo chmod -R ugo+rwx /usr/local/lib
  • Use <CTRL> + C lowers the local server.

Deploying to a cloud server

You can deploy this app to any platform that supports Node.js. Here’s a way to deploy it to Heroku as an example:

  1. Create Heroku & GitHub accounts, sign in to both.
  2. Heroku dashboard: click new > create new pipeline.
  3. Name the pipeline & connect your GitHub repo (select your org, search for the repo).
  4. Pipeline dashboard: click Add app… under Staging – create new, name it – create new app.
  5. Go to Staging > Overview > Configure Add-ons.
  6. Search for and add the following: Heroku SchedulerJawsDB MySQLPapertrailRedis To Go.
  7. Go to Staging > Settings > Reveal Config Vars

Add the following:

  • sails_environment = staging
  • sails_session_url = copy/paste pre-filled REDISTOGO_URL here
  • sails_sockets_url = same Redis to Go URL
  • TZ = customize the timezone used in your Papertrail logs e.g. America/California
  • sails_datastores__default__adapter = sails-sql
  • sails_datastores__default__url = copy/paste pre-filled JAWSDB_URL here
  • sails_log__level = info
  • sails_custom__avimesaApiKey = your Avimesa API key
  • sails_custom__avimesaApiPassword = your Avimesa API password
  • sails_custom__avimesaHostname = your Avimesa Hostame url
  • sails_custom__avimesaTestDeviceId = your Avimesa Device ID
  1. Go to Staging > Deploy > Automatic deploys: Set branch to “deploy” and “Enable”.
  2. Go to Open App and copy your staging url.
  3. Open config/env/staging.js in your project: add your staging url to onlyAllowOrigins and baseUrl (no trailing slash).
  4. Open Terminal, navigate to your GitHub repo & run npm install sails-sql (push up package-lock.json & package.json after).
  5. Double check everything is saved/pushed up & run sails run deploy
  6. Wait for the staging deploy to finish in Heroku, open your staging url.
  7. Enjoy your deployed app!

Deploying to production

You can deploy this app to any platform that supports Node.js. Here’s a way to deploy it to Heroku as an example:

  1. Complete the Staging deploy above first & go to your Pipeline dashboard.

  2. Click Add app… under Production – create new, name it – create new app.

  3. Go to Production > Overview > Configure Add-ons.

  4. Search for and add the following: Heroku SchedulerJawsDB MySQLPapertrailRedis To Go.

  5. Go to Production > Settings > Reveal Config Vars

Add the following:

  • sails_environment = production
  • sails_session_url = copy/paste pre-filled REDISTOGO_URL here
  • sails_sockets_url = same Redis to Go URL
  • TZ = add timezone e.g. America/California
  • sails_datastores__default__adapter = sails-sql
  • sails_datastores__default__url = copy/paste pre-filled JAWSDB_URL here
  • sails_log__level = info
  • sails_custom__avimesaApiKey = Avimesa API key
  • sails_custom__avimesaApiPassword = Avimesa API passwordv
  • sails_custom__avimesaHostname = _Avimesa Hostame urlv
  • sails_custom__avimesaTestDeviceId = _Avimesa Device ID
  1. Go to Open App and copy your production url.

  2. Open config/env/production.js in your project: add your production url to onlyAllowOrigins and baseUrl (no trailing slash).

  3. In config/env/production.js uncomment the following:

  • adapter: '@sailshq/connect-redis', under session and sockets
  • adapter under datastores default and make it: adapter: 'sails-sql'
  • trustProxy: true, under http.
  1. Double check everything is saved/pushed up & run sails run deploy which deploys these changes to staging first.

  2. Wait for the staging deploy to finish, then click Promote to Production, & open your production url.

  3. Enjoy your deployed app!

Production database migrations

You can migrate your DB to any platform that supports it. Here’s a way to migrate your local DB / bootstrap to JawsDB MySQL in Heroku as an example:

  1. Open Terminal, navigate to your GitHub repo and paste the following but don’t submit just yet:

    sails_datastores__default__adapter=sails-sql sails_datastores__default__url=MYSQL_URL_GOES_HERE sails console –drop

  2. Replace MYSQL_URL_GOES_HERE with the full SQL url from your JawsDB MySQL in Staging and submit.

  3. Kill your sails console & run sails console --drop to reset your local DB.

  4. Replace MYSQL_URL_GOES_HERE with the full SQL url from your JawsDB MySQL in Production and submit.

  5. Kill your sails console and run sails console --drop to reset your local DB again.

  6. Verify staging & production DB migrations were successful with Sequel Pro and/or their Heroku urls.

Links

Version info

This app was originally generated on Tue Jul 02 2019 17:30:45 GMT-0500 (Central Daylight Time) using Sails v1.2.3.

This project’s boilerplate is based on an expanded seed app provided by the Sails core team to make it easier for you to build on top of ready-made features like authentication, enrollment, email verification, and billing. For more information, visit Sails.js.