Giter VIP home page Giter VIP logo

greenhouse's Introduction

Greenhouse

automate your greenhouse with a Raspberry Pi zero some sensors and firebase.

You can read more about how this project was made on kalleott.de/iot

Getting started

Install dependencies

npm install
cd functions
npm install
cd ..

UI Code

The UI code for this application is react based and enables you to see the current greenhouse state (temperature, air humidity and soil moisture values). With a slider you can edit the current reference value to determine "dry" moisture values. It is dry when the sensor value is bigger than the reference value.

Device Code

The code running on the Raspberry Pi is located in the device/index.js file. It can be started with 2 arguments, the interval in milliseconds (-interval 60000 or --verbose 60000) in which the sensors should trigger and a verbose (-v or --verbose) flag for more logging. The default interval is 1800000 which is equivalent to 30 minutes.

node index.js -v -i 5000

The wiring diagram can be seen in the greenhouse-schematics.png image.

For the connection to firebase generate a new private key in "service accounts" of the project settings in the firebase console and save it as firebase-key.json in the same folder as the device app on the Raspberry Pi.

Serverless Code

To add functions to your project you can init a project in the functions directory with the command firebase init. This project has a main index.js file and every exported function (exports.functionName) is deployed as a firebase function.

For example the function to check if the plants are dry on a new soil sensor value looks like this:

exports.checkIfPlantsAreDryOnSensorChange = functions.firestore
  .document('/soilMoistureData/{eventId}')
  .onCreate(async snap => {
    const sensorValue = snap.data().value

    const reference = await getDryReferenceValue()

    updateIsDry(sensorValue, reference)
  })

To learn more take a look in the functions/index.js file.

Open ToDos to get started with your own application

firebase

  • install firebase-tools:
    • npm install -g firebase-tools
  • login with the firebase tools
    • firebase login
  • connect to an existing firebase project
    • firebase use
  • change firebase API keys and URLs to use your own project

This application uses an gmail account to send emails to listed users in the users collection when the soil gets dry. So you need to use an existing account or create a new one. To enable the cloud functions to send emails you must set 2 environment variables for firebase:

firebase functions:config:set [email protected]
firebase functions:config:set gmail.password=thePasswordForThisAccount

To deploy the application start with building the UI app, then run the firebase deploy command:

npm run build
firebase deploy

greenhouse's People

Watchers

 avatar

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.