Coder Social home page Coder Social logo

iot-sensors-mqtt-openfaas's Introduction

Deploy OpenFaaS on Swarm

Follow the guide: https://docs.openfaas.com/deployment/docker-swarm/

Deploy InfluxDB and Grafana

docker stack deploy monitor -c docker-compose.yml

Create initial database

curl -XPOST "http://127.0.0.1:8086/query" \
--data-urlencode "q=CREATE DATABASE iot_environment"

Create a Python3 function

Replace alexellis2 with your name on the Docker Hub.

faas-cli new --lang python3 accept-sample --prefix=alexellis2

Now edit accept-sample/requirements.txt:

influxdb

Edit accept-sample.yml and add the environmental variables:

    environment:
       influx_host: influxdb
       influx_port: 8086
       influx_db: iot_environment

Now create secure secrets for your username/password for InfluxDB:

echo -n root | docker secret create influx-user -
echo -n root | docker secret create influx-pass -

Add a section under the function for the secrets:

    secrets:
       - influx-user
       - influx-pass

Create the handler:

Copy the example handler.py from the GitHub repo.

Build/push/deploy the function

You'll need a Docker Hub account for this step.

faas-cli build -f accept-sample.yml && \
faas-cli push -f accept-sample.yml && \
faas-cli deploy -f accept-sample.yml --network=func_functions && \
docker service update accept-sample  --network-add=monitor_monitoring

# Update the function to access the monitoring services

Send a fake sensor reading

echo -n '
{ "sensor": "s1",
  "temp": "30.4",
  "humidity": "54.2"
}
' | curl -i -XPOST -H "Content-Type: application/json" \
  http://127.0.0.1:8080/function/accept-sample --data-binary @- 

Create the dashboard

Now you can set up the data-source for InfluxDB in Grafana.

Navigate to the Grafana interface at: http://127.0.0.1:3000, use admin/admin to log in and create your new password.

Import the data-source for InfluxDB:

curl -H "Content-Type: application/json" \
-X POST http://admin:[email protected]:3000/api/datasources --data-binary '
{
  "id": 1,
  "orgId": 1,
  "name": "influx",
  "type": "influxdb",
  "typeLogoUrl": "public/app/plugins/datasource/influxdb/img/influxdb_logo.svg",
  "access": "proxy",
  "url": "http://influx:8086",
  "password": "root",
  "user": "root",
  "database": "iot_environment",
  "basicAuth": false,
  "isDefault": false,
  "jsonData": {
    "keepCookies": []
  },
  "readOnly": false
}'

Now create the dashboard:

curl -H "Content-Type: application/json" \
-X POST http://admin:[email protected]:3000/api/dashboards/db --data-binary @./dashboard.json

Set up the MQTT broker

You can now set up the MQTT broker to start forwarding sensor readings from the MQTT topic to OpenFaaS. OpenFaaS will call into InfluxDB to store the readings.

Follow the instructions in the mqtt-broker folder.

You can then view the readings using the Grafana dashboard we created above.

iot-sensors-mqtt-openfaas's People

Contributors

alexellis avatar utsavanand2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

iot-sensors-mqtt-openfaas's Issues

Do not accept "faas" as a provider in accept-sample.yml file

Problem

Following README instruction after entering blow command I got ['openfaas'] is the only valid "provider.name" for the OpenFaaS CLI, but you gave: faas

faas-cli build -f accept-sample.yml && \
faas-cli push -f accept-sample.yml && \
faas-cli deploy -f accept-sample.yml --network=func_functions && \
docker service update accept-sample  --network-add=monitor_monitoring

Solution

It seems faas-cli new version doesn't accept "faas" as a provider. To solve this in accept-sample.yml change the provider to openfaas.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.