/js-iot-proxy

Primary LanguageJavaScriptMIT LicenseMIT

IoTSK

This is a demo project used to programmatically interact with two Arduino IoT Cloud Things by taking the properties of the THING_ID_FROM and forward them to THING_ID_TO, in a simple proxy-like pattern. It also exposes a simple http server used to programmatically change the properties of the things.

Things can be associated to one or more real device.

The NodeJs application, that acts as the proxy between the Things, is deployed to Heroku.

This project is also intended as a primer for the following software:

  • Arduino iot-js, used to subscribe to the mqtt broker and being able to read and send data
  • Arduino iot-api JS client, used to interrogate Arduino IoT cloud endpoints
  • Heroku CLI, used to run the NodeJs application locally and deploy it in the cloud

👩‍🚀 Pre-requisites

🚀 Local development Quickstart

  1. Install npm dependencies

    npm i
  2. Create a .env file in the project root. IOT_CLIENT_ID and IOT_CLIENT_SECRET can be generated in the Arduino IoT Cloud. THING_ID_FROM and THING_ID_TO are the IDs of your Things. Those are described in both the sketch file and the Arduino IoT Cloud

    IOT_CLIENT_ID=<arduino iot key>
    IOT_CLIENT_SECRET=<arduino iot secret>
    THING_ID_FROM=<the id of the thing used as source>
    THING_ID_TO=<the id of the thing used as destination>
  3. Setup Heroku

    • Create an account if you don't have one
    • Install Heroku CLI
    • login running heroku login in your shell
    • run heroku create in the project root directory
  4. Run your app locally on http://localhost:3000

    • via heroku local
    • with the provided launch configuration if you are using VSCode
    • via npm start

📖 API Docs

Server endpoints are documented using Swagger and jsDoc. Once the server is running on your local machine just visit http://localhost:3000/docs to view the docs and try the APIs!