Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

N+(2) Aquarium Controller

N+2 aquarium webserver scheduler plugin json html POST

  • Please log in to reply
75 replies to this topic

#1 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 01 September 2012 - 06:05 PM

UPDATE: 2013-02-01

I've finally got around to some more updates, and the system is now to a point I can use it in production!

Webserver is now working (thanks to the great code from the NeonMika webserver project) and the web front end is functional.  

 

Next task is to get the web front end to restart the controller on demand.

 

OH, and it's all running on a N+2 now.  I'm going to backport to original N+ when I'm feature complete, just waiting on the next .netmf runtime to start that branch

 

The Controller looks after my 90 Gallon Reef Tank and has a number of different features that some people could find helpful.
Highlights include:


    [*]Plugin style architecture, controlled via JSON config file. Allows dynamic loading of plugins from SD Card on power up
    [*]Dynamic Web Front end provides config options and current system status using html and JS. The controller builds out an index.html file on boot based on the json config and allows settings to be changed (light timers, etc)
    [*]Handles input sensors (currently Temp and pH), multiple output options (log file on SD, Thingspeak) and Control functions (Relays for lights and solenoids for water levels), each driven by their own 'plugin'
    [*]Custom 'scheduler' to handle all events and timers
    [/list]

    Please check things out at [url="[url="https://github.com/h07r0d/Netduino-Aquarium-Controller"]https://github.com/h07r0d/Netduino-Aquarium-Controller"]github[/url][/url] or follow along at http://fishfornerds.com

    Also, if the sln doesn't build, please let me know, I have some file move build rules that may be getting in the way...

    Attached Files


    Edited by H07R0D, 01 February 2013 - 08:19 PM.


#2 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 02 September 2012 - 02:27 PM

Hi, I too am slowly building an aquarium controller, so it is interesting to see another approach! I see you have gone for the relay control board, I decided a slightly different route and build my own relay controller which I am just finishing off designing the thermal protection circuit for. In terms of sensors what things are you thinking of measuring and have you made any decisions in terms of which sensors you will be using? E.g. DS18B20's for temperature etc? I found some great water chemistry sensors from Atlas scientific, so far I haven't done much with the Ph one I have bought, but they seem to make life a lot easier from an electronics point of view and are very accurate. Have you got any plans to go down the N Go route? Cheers, Andy

#3 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 02 September 2012 - 10:06 PM

Hi,

I too am slowly building an aquarium controller, so it is interesting to see another approach!

I see you have gone for the relay control board, I decided a slightly different route and build my own relay controller which I am just finishing off designing the thermal protection circuit for. In terms of sensors what things are you thinking of measuring and have you made any decisions in terms of which sensors you will be using? E.g. DS18B20's for temperature etc?

I found some great water chemistry sensors from Atlas scientific, so far I haven't done much with the Ph one I have bought, but they seem to make life a lot easier from an electronics point of view and are very accurate.

Have you got any plans to go down the N Go route?

Cheers,

Andy


Hi Andy,
Thanks for the reply. I went with the relay shield as this is my first real foray into hardware and I felt a bunch of relays were beyond my ken.

As for sensors, I went with a simple thermistor for temp (this one) as I needed something waterproof that wasn't metal.
I did go with Atlas Scientific for the pH and used their pH stamp which was hella easy to wire up to the netduino.
I'm not sure what else to go with in terms of inputs, those are the big two for me.

I really like the modular nature of the Go, but getting things into a waterproof case and still get enough cables in and out seems tricky enough with just a couple of shields. I can't imagine routing everything and then adding modules too.

#4 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 04 September 2012 - 06:19 PM

I am looking at temperature sensors, Ph, lighting control, a separate relay unit with temperature control and then maybe something like water level sensors, solenoids for dosing, auto feeders, stray current sense, leakage detection etc. I haven't wired my Ph Stamp up yet but look forward to trying it out soon, have you thought of an of Atlas' other sensors ORP etc? I am also using a gainspan wireless module as I plan to make a web interface for it, are you planning any web interface? Andy

#5 zemuss

zemuss

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 25 October 2012 - 06:33 PM

Hotrod, have you upgraded this to 4.2 yet? if so did you have an issue with the AnalogInput in the Temp Project?

#6 strent

strent

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 27 October 2012 - 07:10 AM

zemuss - To fix the AnalogInput error add a reference to SecretLabs.NETMF.Hardware.AnalogInput H07R0D - The Json config deserializing seems to be broken? (I already figured out the example config is in the wrong format but still can't get it to work)

#7 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 27 October 2012 - 12:36 PM

Hotrod,

have you upgraded this to 4.2 yet? if so did you have an issue with the AnalogInput in the Temp Project?

Zemuss, when I went up to 4.2I had to drop all the references in the temp project, and re-add them. For some reason, the path for the analog input was wrong.

#8 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 27 October 2012 - 12:38 PM

zemuss - To fix the AnalogInput error add a reference to SecretLabs.NETMF.Hardware.AnalogInput


H07R0D - The Json config deserializing seems to be broken? (I already figured out the example config is in the wrong format but still can't get it to work)

Strent, I'm not sure what would be causing the problem. When I went up to the full 4.2 I've been having trouble getting the mac address to stick on my n+, so I haven't been looking at much else. I'll take a look and see what's going on.

#9 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 27 October 2012 - 12:43 PM

I am looking at temperature sensors, Ph, lighting control, a separate relay unit with temperature control and then maybe something like water level sensors, solenoids for dosing, auto feeders, stray current sense, leakage detection etc.

I haven't wired my Ph Stamp up yet but look forward to trying it out soon, have you thought of an of Atlas' other sensors ORP etc?

I am also using a gainspan wireless module as I plan to make a web interface for it, are you planning any web interface?

Andy

Hi Andy,
I've got the web interface built and its functional, but I need a thin webserver that will accept files in a post. The web interface edits the config.js file on the client, so I need a way to save it back to the sd card.

#10 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 29 October 2012 - 09:29 PM

Good work on the web interface! What have you written your web interface with and what database back end are you using?

Are you data logging locally on your device or are you writing back to your web server? Or are you planning on doing a bit of both i.e. log the data locally and then poll the data in chunks back to your web server?

I think I am planing on the latter to make sure if there are any connection issues at the point of polling you can continue to log the data. I don't know if your interested in tracking environmental changes but I do a lot of data visualisation and analysis at work and want to do the same with my aquarium.

In terms of your config.js try ConfigManager as in this.

You may also have to work in your sd save methods.

If commands are coming from your web interface you would have to write a http receiver method to handle the config update request.

Andy

#11 zemuss

zemuss

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 30 October 2012 - 01:25 AM

I just tried using the namespace recommended again and received this error "Error 2 The type or namespace name 'AnalogInput' does not exist in the namespace 'SecretLabs.NETMF.Hardware' (are you missing an assembly reference?) C:\Development\Code Examples\Netduino-Aquarium-Controller\Plugin-Temperature\Temperature.cs 5 33 Plugin-Temperature" "Z"

#12 zemuss

zemuss

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 30 October 2012 - 02:22 PM

Ok I dropped all references and the code works. Minor tweak = AnalogInput ain = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); HotRod let me know if you need any other help.

#13 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 31 October 2012 - 02:04 PM

I just tried using the namespace recommended again and received this error "Error 2 The type or namespace name 'AnalogInput' does not exist in the namespace 'SecretLabs.NETMF.Hardware' (are you missing an assembly reference?) C:\Development\Code Examples\Netduino-Aquarium-Controller\Plugin-Temperature\Temperature.cs 5 33 Plugin-Temperature"

"Z"


I do recall seeing this. For some reason, whenever I was re-adding the reference, it kept using the file from the project itself, instead of the dll in the runtime locations.
I ended up manually adding a reference to the specific file in the runtime library, instead of picking the reference from the list, and that fixed it for me.

#14 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 31 October 2012 - 06:21 PM

Good work on the web interface! What have you written your web interface with and what database back end are you using?

Are you data logging locally on your device or are you writing back to your web server? Or are you planning on doing a bit of both i.e. log the data locally and then poll the data in chunks back to your web server?

I think I am planing on the latter to make sure if there are any connection issues at the point of polling you can continue to log the data. I don't know if your interested in tracking environmental changes but I do a lot of data visualisation and analysis at work and want to do the same with my aquarium.

In terms of your config.js try ConfigManager as in this.

You may also have to work in your sd save methods.

If commands are coming from your web interface you would have to write a http receiver method to handle the config update request.

Andy

Hi Andy,
The web interface is just straight html & javascript. On device boot, initialization loops through each plugin and pulls small html fragments to build the index.html file.
That way, new plugins are picked up so long as they are in the config.js file

The web interface only does controller config, any data logging is done through the respective plugins. Currently there's logfile (just csv on the sd card) and Thingspeak channels. They have some minor config options on index.html, but I didn't add any ability to pull the logfile from the sd card through the browser. I like that idea though.

I ended up going with the .js config file because it lets me use the web interface to edit config data without needing to write my own parsers. All modern browsers will write js objects to text, so that made life much easier.

As for the commands, each plugin that has functions for the web interface registers handlers to the webserver. For example, the Relay plugin has a handler for turning on and off specific ports. I register the handler in the webserver with a specific url in mind (ie 192.168.1.140/relay/2/on) and there's a callback in the relay plugin that the webserver can call.
So in the Relay section of index.html there are 4 on/off buttons. Each of those buttons fires an ajax event that the web server will catch, search for the registered handler and execute it.
Of course, I still need to get the bloody web server working on the netduino, so some of that is theoretical.

#15 zemuss

zemuss

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 01 November 2012 - 01:06 AM

One of the things I want to do with the controller is create a website and data storage. I was thinking SQL express because I hate storing data in CSV files. Maybe a small access database? WHy did you pick JS versus using a XML document for the config file? Was the XML getting to big or was it just because of the parsing reasons?

#16 strent

strent

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 01 November 2012 - 01:16 PM

I managed to get it working on my Netduino! Few things... Referencing SecretLabs.NETMF.Hardware.AnalogInput will not work. Although it will let you compile - it can't find the assembly on the device. Updating the analog input reference to .net mf 4.2's method will fix the issue (AnalogInput ain = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);). However, AnalogInput() now returns a double instead of a float. I went and changed all references from floats to doubles to fix this issue (it seems most of the time the float was being cast to a double anyway). The example config will not work. You'll need to prefix the JSON with var config= and put ; at the end. You'll then need to update JSON.cs - configString = configString.Substring(12, configString.Length - 13); The thingspeak/aquariumstatus plugins threw errors for me - but I just disabled them for the moment. H07R0D - your code is exactly what I'm looking for and I plan on using it to write an output plugin to post data to my website. Thanks!

#17 zemuss

zemuss

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 01 November 2012 - 02:24 PM

Strent

You can always use this code:

In the CalculateTemperature method, I added the following changes:
AnalogInput ain = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);
// take 10 readings to even out the noise
float average = 0.0F;
for (int i = 0; i < 10; i++) { average += (int)ain.Read(); } // ain.Read(); }
average /= 10;

(int) before the ain.read will convert from double to integer.

#18 strent

strent

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 01 November 2012 - 02:27 PM

Thanks zemuss, didn't think of that. Another issue I came across - when I was trying to debug why the config wasn't working, I found that the contents of the HashTable does not show correctly in Visual Studio (was pulling my hair out on this one for a while). If you iterate through it and dump it to the output window it shows correctly.

#19 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 01 November 2012 - 02:31 PM

One of the things I want to do with the controller is create a website and data storage. I was thinking SQL express because I hate storing data in CSV files. Maybe a small access database?

WHy did you pick JS versus using a XML document for the config file? Was the XML getting to big or was it just because of the parsing reasons?


Getting any form of SQL running on a tiny little Netduino would be impressive to say the least. There's just not enough space to run such a complex piece of code. If you had your netduino sending plain text to a different server somewhere that could then dump the received data into a table, that would work for sure. Having the netduino writing data straight to an access database format would be tough.

I went JS because I could get a very lightweight static parser. If I enabled the XML libraries, even the .NET-MF ones, I lost most of my program space on the N+. Going JS let me keep moving forward with a rather large amount of code.

#20 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 01 November 2012 - 02:34 PM

Thanks zemuss, didn't think of that.



Another issue I came across - when I was trying to debug why the config wasn't working, I found that the contents of the HashTable does not show correctly in Visual Studio (was pulling my hair out on this one for a while). If you iterate through it and dump it to the output window it shows correctly.


I completely forgot to update the .example file with the config var wrapper! Crap!
I'll be sure to update that asap.
I ended up wrapping it so a browser could load the whole thing as a single var I could reference. If I didn't wrap it, then any access in browser JS needed to be through 'input, output, control' vars.
If anyone has a better idea, I'm all ears for that.


As for the display stuff, VS doesn't have a built-in HashTable visualizer like it does for other object types.
I found a couple tutorials here and there, but never got around to writing my own visualizer.
Google 'visual studio hashtable visualizer' and got a few hits worth looking at.





Also tagged with one or more of these keywords: N+2, aquarium, webserver, scheduler, plugin, json, html, POST

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.