element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Vertical Farming
  • Challenges & Projects
  • Design Challenges
  • Vertical Farming
  • More
  • Cancel
Vertical Farming
Blog Vertical Hydroponics: Blog 5 - Web Interface
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jamesod
  • Date Created: 17 Sep 2015 3:41 AM Date Created
  • Views 526 views
  • Likes 1 like
  • Comments 4 comments
  • vertical
  • hydroponics
  • web_interface
  • vertical_farming
  • node.js
Related
Recommended

Vertical Hydroponics: Blog 5 - Web Interface

jamesod
jamesod
17 Sep 2015

Vertical Hydroponic System Web Interface Part 1:

 

Last week I began work on replacing OpenHAB as the web interface. I still have a lot left to do, but I thought it best to give an update since I have gotten the basic framework working. I am using a BeagleBone Black as the hardware for the webserver. I am using a Debian image for the OS and this is an older version of the BBB so I have to run off of an 8 gb SD card. I am using the standard image found here: http://beagleboard.org/latest-images. Creating a custom image is on the list of to-dos, but it is a low priority at the moment.

I decided to use node.js with express for the webserver. I will be using socket.io for data transmission, and d3.js for client side visualization and interaction. Using these packages means that my package.json file looks like this:

 

{
  "name": "Hydro Shelves",
  "version": "0.0.1",
  "description": "WebSCADA for Hydro System",
  "main": "hydro1.js",
  "dependencies": {
  "express": "4.10.2",
  "socket.io": "^1.3.5",
  "d3": "3.5.5"
  }
}

I created a new directory in the root folder called hydro1. I placed the package.json file in there along with my main file hydro1.js and the hydro1.html file I will be serving. Then I ran: npm install to download the dependencies. These are automatically placed in a new folder called node_modules.

I also created a folder called data and put a text file called main_data.txt in it. Then I made another folder called images. I created simple images of the different parts of my hydroponics system to indicate whether they are on or off and put them in the images folder.

 

To give a basic idea of what is happening, I have a text file called main_data.txt. This will be used to store the current values of the important variables to display. When a user connects to the webserver, hydro1.js will serve hydro1.html, and open a socket connection with the user's browser to transmit the data. Every second the text file is read and data is sent through the socket. The client side code reads the transmitted data and uses it to create objects suitable for display. The d3.js code then displays different images and text values based on the state of the system.


I created a script called fakedata.js to change the state of a few variables in the text file every five seconds. Doing it this way I can verify that changes to the text file are properly displayed on the webpage. To have this script run automatically in the background, I created a file called fakedata.service:

 

[Unit]

Description=FakeData Running continuously in background

After=network.target


[Service]

ExecStart=/usr/bin/node /home/root/hydro1/fakedata.js

Environment=NODE_ENV=production

Restart=always

RestartSec=10s


[Install]

WantedBy=multi-user.target


then I placed the file in /lib/systemd/system and ran:

systemctl enable fakedata.service

systemctl start fakedata.service


Finally in the /hydro1 folder I ran:

node hydro1.js


This resulted in the following being displayed on port 8181:


image

and when the data changes:

image


I have verified that this works. So I know that as long as I change the data in the text file I can get what I want displayed on the webpage.


I have attached all of the files I am using. Warning: this code is in a barely usable state. I am pretty new to JavaScript and still don't really understand a lot of how it works. I did enough to get the basics working. The code is not commented well, is inefficient, and may be difficult to follow. I've attached it just so that people can see how I am doing this and ask questions or give criticism if they like.


I have a lot of plans for improving this code and I will probably be creating a github repo for this project. I will be adding the ability to select and graph data. I also want to add the ability to click on a component and change the control parameters. By the end of this contest I want to have this done, and the code in good enough condition so that it is usable by others. All comments and criticisms are appreciated. 

Attachments:
hydro1_images.zip
nodejs.zip
  • Sign in to reply

Top Comments

  • DAB
    DAB over 10 years ago +1
    Looks good. I look forward to seeing your system in operation. DAB
  • amgalbu
    amgalbu over 10 years ago in reply to jamesod

    Hi James

    Sorry I misread your post: I thought you were going to replace only the web interface, not the whole OpenHAB platform!

     

    Cheers

    Ambrogio

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jamesod
    jamesod over 10 years ago in reply to amgalbu

    Actually Ambrogio I decided to move away from OpenHAB. I am building a solution with JavaScript using node.js. All of the hardware I'm using will be custom, and I want a much more visual custom dashboard/SCADA type interface so OpenHAB just isn't the right fit anymore. I used it for awhile when I just wanted very basic information and it worked well for about a year.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • amgalbu
    amgalbu over 10 years ago

    Really a good idea to use a platform like OpenHAB for controlling the farm

    Are there ready-to-use bindings for you sensors or you are going to develop new ones?

     

    Cheers

    Ambrogio

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 10 years ago

    Looks good.

     

    I look forward to seeing your system in operation.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube