Click here to Skip to main content
15,881,803 members
Articles / Internet of Things / Arduino
Article

Plant Lighting System in Python

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
11 Apr 2017CPOL8 min read 9.1K   3  
This Plant Lighting System application is part of a series of how-to Intel® Internet of Things (IoT) code sample exercises using the Intel® IoT Developer Kit, Intel® Edison board, Intel® IoT Gateway, cloud platforms, APIs, and other technologies.

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Get access to the new Intel® IoT Developer Kit, a complete hardware and software solution that allows developers to create exciting new solutions with the Intel® Galileo and Intel® Edison boards. Visit the Intel® Developer Zone for IoT.

Introduction

This Plant Lighting System application is part of a series of how-to Intel® Internet of Things (IoT) code sample exercises using the Intel® IoT Developer Kit, Intel® Edison board, Intel® IoT Gateway, cloud platforms, APIs, and other technologies.

From this exercise, developers will learn how to:

  • Connect the Intel® Edison board or Intel® IoT Gateway, computing platforms designed for prototyping and producing IoT and wearable computing products.
  • Interface with the Intel® Edison board or Arduino 101* (branded Genuino 101* outside the U.S.) board IO and sensor repository using MRAA and UPM from the Intel® IoT Developer Kit, a complete hardware and software solution to help developers explore the IoT and implement innovative projects.
  • Store the Plant Lighting System data using Azure Redis Cache* from Microsoft Azure*, Redis Store* from IBM Bluemix*, or ElastiCache* using Redis* from Amazon Web Services (AWS)*, different cloud services for connecting IoT solutions including data analysis, machine learning, and a variety of productivity tools to simplify the process of connecting your sensors to the cloud and getting your IoT project up and running quickly.
  • Set up a MQTT-based server using IoT Hub from Microsoft Azure*, IoT from IBM Bluemix*, or IoT from Amazon Web Services (AWS)*, different cloud machine to machine messaging services based on the industry standard MQTT protocol.
  • Invoke the services of the Twilio* API for sending text messages.

What it is

Using an Intel® Edison board or Intel® IoT Gateway, this project lets you create an automatic plant lighting monitor system that:

  • uses a light sensor to determine if a separate automated lighting system is turned on or off based on a configurable schedule.
  • can be accessed with your mobile phone via the built-in web interface to set the lighting times.
  • monitors the water levels using a connected moisture sensor.
  • logs events from the lighting system using cloud-based data storage.
  • sends text messages to alert recipients if the system if not working as expected.

How it works

The system allows setting the lighting schedule via a web page served directly from the Intel® Edison board or Intel® IoT Gateway by using your mobile phone.

If the lighting is supposed to be on, but the light sensor does not detect any light, it sends a text alert to a specified number through Twilio*.

It also automatically checks and logs moisture sensor data at periodic intervals.

Optionally, all data can be stored using the Intel® IoT Examples Datastore or an MQTT server running in your own Microsoft Azure*, IBM Bluemix*, or AWS* account.

Hardware requirements

This sample can be used with either the Grove* Indoor Environment Kit from Seeed Studio, or else the DFRobot* Starter Kit for Intel® Edison board along with some additional DFRobot* parts.

Grove* Indoor Environment Kit, containing:

  1. Intel® Edison with an Arduino* breakout board or Intel® IoT Gateway with Arduino 101* (branded Genuino 101* outside the U.S.)
  2. Grove* Moisture Sensor
  3. Grove* Light Sensor
  4. Grove* RGB LCD

DFRobot* Starter Kit for Intel® Edison containing:

  1. Intel® Edison board with an Arduino* breakout board or Intel® IoT Gateway with Arduino 101* (branded Genuino 101* outside the U.S.)
  2. Moisture Sensor.
  3. Analog Ambient Light Sensor
  4. LCD Keypad Shield

Software requirements

  1. Microsoft Azure*, IBM Bluemix*, or AWS* account (optional)
  2. Twilio* account (optional)

Connecting the Grove* sensors

Image 1

You need to have a Grove* Shield connected to an Arduino* compatible breakout board to plug all the Grove* devices into the Grove* Shield. Make sure you have the tiny VCC switch on the Grove* Shield set to 5V.

  1. Plug one end of a Grove cable into the Grove* Light Sensor, and connect the other end to the A2 port on the Grove* Shield.

  2. Plug one end of a Grove cable into the Grove* Moisture Sensor, and connect the other end to the A3 port on the Grove* Shield.

  3. Plug one end of a Grove cable into the Grove* RGB LCD, and connect the other end to any of the I2C ports on the Grove* Shield.

Connecting the DFRobot* sensors

Image 2

You need to have a LCD Keypad Shield connected to an Arduino* compatible breakout board to plug all the DFRobot* devices into the LCD Keypad Shield.

  1. Plug one end of a DFRobot* cable into the Analog Ambient Light Sensor, and connect the other end to the A1 port on the LCD Keypad Shield.

  2. Plug one end of a DFRobot* cable into the Moisture Sensor, and connect the other end to the A2 port on the LCD Keypad Shield.

Intel® Edison board setup

If you're running this code on your Intel® Edison board, you need to install some dependencies by establishing an SSH session to the board running the following commands.

To install Git* on the Intel® Edison board (if you don’t have it yet), establish an SSH connection to the board and run the following command:

$ opkg install git

To obtain the Python* packages needed for this example to execute on the Intel® Edison board:

Run the following commands to update to the latest version of Python's package installer:

$ pip install --upgrade pip setuptools

Run the following to update to the latest versions of the MRAA and UPM libaries:

$ echo "src mraa-upm http://iotdk.intel.com/repos/3.5/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf
$ opkg update
$ opkg install mraa upm

Once the dependencies are installed you can install the example itself with the following command:

$ pip install --src ~/python/examples/ -e "git+https://github.com/intel-iot-devkit/how-to-code-samples.git#egg=iot_plant_lighting_system&subdirectory=plant-lighting-system/python"

The pip command will install required Python dependencies, save the source code for the example in ~/python/examples/iot_plant_lighting_system/ and link the package to the global Python site-packages folder.

Intel® IoT Gateway setup

You can run this example using an Intel® IoT Gateway connected to an Arduino 101*(branded Genuino 101* outside the U.S.) board.

Make sure your Intel® IoT Gateway is setup using Intel® IoT Gateway Software Suite, by following the directions on the web site here:

https://software.intel.com/en-us/getting-started-with-intel-iot-gateways-and-iotdk

To install and run the example, you will need to install Python setuptools. This is easy to do, by running:

$ wget https://bootstrap.pypa.io/ez_setup.py -O - | python

Once these dependencies are installed you can install the example itself with the following command:

$ pip install --src ~/python/examples/ -e "git+https://github.com/intel-iot-devkit/how-to-code-samples.git#egg=iot_plant_lighting_system&subdirectory=plant-lighting-system/python"    

The pip command will install required Python dependencies, save the source code for the example in ~/python/examples/iot_plant_lighting_system/ and link the package to the global Python site-packages folder.

The Arduino 101 needs to have the Firmata* firmware installed. If you have IMRAA installed on your gateway, this will be done automatically. Otherwise, install the StandardFirmata or ConfigurableFirmata sketch manually on to your Arduino 101.

You will also need to configure the config.json in the example to use the Arduino 101. See the section "Configuring the example" below.

Twilio* API key

To optionally send text messages, you need to register for an account and get an API key from the Twilio* website:

https://www.twilio.com

You cannot send text messages without obtaining a Twilio API key first. You can still run the example, but without the text messages.

Data store server setup

Optionally, you can store the data generated by this sample program in a back-end database deployed using Microsoft Azure*, IBM Bluemix*, or AWS*, along with Node.js*, and a Redis* data store.

For information on how to set up your own cloud data server, go to:

https://github.com/intel-iot-devkit/intel-iot-examples-datastore

MQTT server setup

You can also optionally store the data generated by this sample program using MQTT, a machine-to-machine messaging server. You can use MQTT to connect to Microsoft Azure*, IBM Bluemix*, or AWS*.

For information on how to connect to your own cloud MQTT messaging server, go to:

https://github.com/intel-iot-devkit/intel-iot-examples-mqtt

Configuring the example

When the example is installed through pip the config.json file that holds the configuration for the example lives in ~/python/examples/iot_plant_lighting_system/plant-lighting-system/python/iot_plant_lighting_system/config.json.

To configure the example for the Grove* kit, just leave the kit key in the config.json set to grove. To configure the example for the DFRobot* kit, change the kit key in the config.json to dfrobot as follows:

{
  "kit": "dfrobot"
}

To configure the example for the Arduino 101* (branded Genuino 101* outside the U.S.), add a platform key with the value firmata to the config.json, as follows:

{
  "kit": "grove",
  "platform": "firmata"
}

To configure the example for sending optional text messages, obtain an API key from the Twilio* web site as explained above, and then add the TWILIO_ACCT_SID and TWILIO_AUTH_TOKEN keys to the config.json file as follows:

{
  "kit": "grove",
  "TWILIO_ACCT_SID": "YOURAPIKEY",
  "TWILIO_AUTH_TOKEN": "YOURTOKEN"
}

To configure the example for both the text messages and the Microsoft Azure*, IBM Bluemix*, or AWS* data store, add the TWILIO_ACCT_SID, TWILIO_AUTH_TOKEN, SERVER, and AUTH_TOKEN keys to the config.json file as follows:

{
  "kit": "grove",
  "TWILIO_ACCT_SID": "YOURAPIKEY",
  "TWILIO_AUTH_TOKEN": "YOURTOKEN",
  "SERVER": "http://Intel-examples.azurewebsites.net/logger/lighting-system",
  "AUTH_TOKEN": "s3cr3t"
}

For information on how to configure the example for the optional Microsoft Azure*, IBM Bluemix*, or AWS* MQTT messaging server, go to:

https://github.com/intel-iot-devkit/intel-iot-examples-mqtt/

Running the program

Once the example is installed through pip you can run the program by running the following command in an SSH session to the board:

$ python -m iot_plant_lighting_system

Determining the Intel® Edison board's IP address

You can determine what IP address the Intel® Edison board is connected to by running the following command:

ip addr show | grep wlan

You will see the output similar to the following:

3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    inet 192.168.1.13/24 brd 192.168.1.255 scope global wlan0

The IP address is shown next to inet. In the example above, the IP address is 192.168.1.13.

IMPORTANT NOTICE: This software is sample software. It is not designed or intended for use in any medical, life-saving or life-sustaining systems, transportation systems, nuclear systems, or for any other mission-critical application in which the failure of the system could lead to critical injury or death. The software may not be fully tested and may contain bugs or errors; it may not be intended or suitable for commercial release. No regulatory approvals for the software have been obtained, and therefore software may not be certified for use in certain countries or environments.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
This is a Organisation

42 members

Comments and Discussions

 
-- There are no messages in this forum --