This is a small example program that showcases a simple application that uses Yggio.
It consists of a backend and a frontend. Both require Node.js to be run.
The backend uses the npm package yggio-connect.
The application does the following:
- Creates a provider
- Creates two example users
- Creates two example iotnodes
- Allows the user to login with OAuth
- Lists the iotnodes
- Allow the user to subscribe to an iotnode (i.e. create a channel)
- Logs received iotnode subscription messages
Note that in order for the app to receive iotnode subscription messages, the app must be exposed to the Internet with a public IP address.
Before running the app, configurations has to be made. The provided default values can be used but PROVIDER_NAME
, YGGIO_ACCOUNT_USERNAME
and YGGIO_ACCOUNT_PASSWORD
need to be set.
The backend is configured in backend/src/config/common.js
:
// The host of yggio-service-example backend
// Will be 127.0.0.1 if backend is run locally
const BACKEND_HOST = '127.0.0.1';
// The port used by the yggio-service-example backend
// Should be the same as in frontend/src/constants/index.js
const BACKEND_PORT = '9999';
// The URL to the yggio-service-example frontend
// Will be http://localhost if frontend is run locally
const FRONTEND_URL = 'http://localhost';
// The port used by the yggio-service-example frontend
// Should be the same as in frontend/.env
const FRONTEND_PORT = '9492';
// The URL of the REST API of the Yggio you want to use
// Should be the same as in frontend/src/constants/index.js
// https://staging.yggio.net is a suitable test server and is set as default
const YGGIO_API_URL = 'https://staging.yggio.net/';
// The name of the provider that is created
// Can be set to anything
const CLIENT_NAME = '';
// Username of the user that creates the provider
// Can be set to anything
const YGGIO_ACCOUNT_USERNAME = '';
// Password of the user that creates the provider
// Can be set to anything
const YGGIO_ACCOUNT_PASSWORD = '';
The frontend is configured in frontend/src/constants/index.js
:
export const statStr = {
backendHost: 'http://localhost:9999',
};
The backend and the frontend requires one terminal instance each. The backend should be started before the frontend.
To start the backend open a new terminal window and run:
cd backend/
npm install
npm start
To start the frontend open a new terminal window and run:
cd frontend/
npm install
npm start
The frontend can be viewed in a browser at the configured address, defaulted to http://localhost:9492/.
To login in with OAuth, use the credientals of the first test user, which is testuser1
as username and password
as password.