Reef Central Online Community

Home Forum Here you can view your subscribed threads, work with private messages and edit your profile and preferences View New Posts View Today's Posts

Find other members Frequently Asked Questions Search Reefkeeping ...an online magazine for marine aquarists Support our sponsors and mention Reef Central

Go Back   Reef Central Online Community > General Interest Forums > Do It Yourself
Register Blogs FAQ Calendar Mark Forums Read

Notices

Reply
Thread Tools
Old 10/18/2017, 02:33 PM   #26
thegasman2000
Registered Member
 
thegasman2000's Avatar
 
Join Date: Dec 2005
Location: Pewsey, England
Posts: 86
Quote:
Originally Posted by perkint View Post
That is pretty much what my controller will do, when I get round to porting it onto the ESP32 or ESP8266. Probably more likely to go with the ESP32 for essentially the same reasons you suggest - still about the same price and more powerful! And Bluetooth built in!

Not sure how accurate the built in time keeping is in the ESPs tho - the Arduinos are pretty inaccurate without an RTC, so would be tempted to include an RTC, but automatically set it from an NTP server when the 'net is available.

Tim
I looked into the ESP32 and the bluetooth is great and all but getting 2 to talk to each other via bluetooth will be a massive pain in the ***! I decided to go for the ESP8266 (cheaper) with a couple of these NRF24L01. This makes it easier to interface 2 or more arduino devices. I suspect I only need 2, a master and a slave for the lights but a slave on the RO storage unit or to run some power monitoring on the relays might also be cool.


__________________
The Google Fu is strong in this one.

Current Tank Info: 90 gallon sumped cube
thegasman2000 is offline   Reply With Quote
Old 10/19/2017, 07:13 AM   #27
perkint
Registered Member
 
Join Date: Jan 2014
Posts: 775
I have a few of the NRF24L01s to, but not actually played with them yet. Seem a reasonable solution for the sort of thing you suggest

Tim


perkint is offline   Reply With Quote
Old 10/26/2017, 02:39 PM   #28
thegasman2000
Registered Member
 
thegasman2000's Avatar
 
Join Date: Dec 2005
Location: Pewsey, England
Posts: 86
Ok So I am close to having the core of the code down, I just need a help getting the LED PWM value from the Get request. Anyone got any ideas...

if (request.startsWith("/whiteLevel=") != -1) {
Serial.println("WHITE LEVEL SET ");
Serial.println(whiteLevel);
analogWrite(whiteLed, whiteLevel);
}

I just need to grab the 3 digits after the = and make that equal to whiteLevel


__________________
The Google Fu is strong in this one.

Current Tank Info: 90 gallon sumped cube
thegasman2000 is offline   Reply With Quote
Old 10/26/2017, 04:15 PM   #29
perkint
Registered Member
 
Join Date: Jan 2014
Posts: 775
Use substring to get the numbers from request and then convert them into an int to assign to whiteLevel (assuming whiteLevel is an int). Assume you'll have to do it in two steps (substring to a string, convert string to int). Does that help or do you want code? No problem if so, but I'd need to check the syntax before offering an example (C++ not a language I use that often...).

Tim


perkint is offline   Reply With Quote
Old 10/26/2017, 04:32 PM   #30
reeferdude710
Registered Member
 
Join Date: Oct 2017
Posts: 10
Thumbs down

lol china i dont support


reeferdude710 is offline   Reply With Quote
Old 10/26/2017, 05:03 PM   #31
thegasman2000
Registered Member
 
thegasman2000's Avatar
 
Join Date: Dec 2005
Location: Pewsey, England
Posts: 86
Quote:
Originally Posted by perkint View Post
Use substring to get the numbers from request and then convert them into an int to assign to whiteLevel (assuming whiteLevel is an int). Assume you'll have to do it in two steps (substring to a string, convert string to int). Does that help or do you want code? No problem if so, but I'd need to check the syntax before offering an example (C++ not a language I use that often...).

Tim
Tim if you could that would be awesome. I have a pastebin here with the cobbled ugly code I currently have.
https://pastebin.com/r9D3h6us


__________________
The Google Fu is strong in this one.

Current Tank Info: 90 gallon sumped cube
thegasman2000 is offline   Reply With Quote
Old 10/26/2017, 05:03 PM   #32
thegasman2000
Registered Member
 
thegasman2000's Avatar
 
Join Date: Dec 2005
Location: Pewsey, England
Posts: 86
Quote:
Originally Posted by reeferdude710 View Post
lol china i dont support
Budget requirements


__________________
The Google Fu is strong in this one.

Current Tank Info: 90 gallon sumped cube
thegasman2000 is offline   Reply With Quote
Old 10/27/2017, 07:29 AM   #33
perkint
Registered Member
 
Join Date: Jan 2014
Posts: 775
Quote:
Originally Posted by thegasman2000 View Post
Tim if you could that would be awesome. I have a pastebin here with the cobbled ugly code I currently have.
https://pastebin.com/r9D3h6us
That makes life easier

Will hopefully have a look tonight or over the weekend. Unless someone beats me to it!

Tim


perkint is offline   Reply With Quote
Old 10/27/2017, 08:39 AM   #34
lingwendil
LED snob & Luxeon fanboy
 
Join Date: Oct 2004
Location: Oakley, behind enemy lines in communist occupied California.
Posts: 146
Quote:
Originally Posted by perkint View Post
Stick an MCP23017 on the ESP via I2C and you can have as many IO pins as you like - just needs the two pins from the ESP and you can add multiple MCP23017s

Tim
Maybe a bit off topic, but is there something similar to the MCP23017 that allows for analog inputs? It sure would be nice to have a little 16 channel analog read functionality with the ESP chips. I have a perverse desire to have each channel knob-adjustable for testing and possible large-scale and/or professional use (for example, over a working display tank at a storefront, ability to show differences in real time is easier with some knobs for adjustment)where simple dimming control is all you need, with individual channel adjustability for tuning color and PAR.

Quote:
Originally Posted by reeferdude710 View Post
lol china i dont support
Way to go, contentless post that adds nothing to the thread, and totally ignores the discussion. (also, I bet that there is a vast pile of chinese products within a few feet of you at any given time, and especially in the internet device you posted this with. Keep on riding that high horse.)

Quote:
Originally Posted by thegasman2000 View Post
I have a pastebin here with the cobbled ugly code I currently have.
https://pastebin.com/r9D3h6us


I'm going to dig through this a while. Have you seen the WifiManager code? Looks like a great way to streamline the initial setup. Although setting the credentials in code isn't difficult for most of us, would be a neat feature, especially for testing on multiple setups at different locations.

https://github.com/tzapu/WiFiManager


__________________
LED snob. Unapologetic Luxeon Rebel and Bridgelux Vero fanboy. Every time a fluorescent or halide fixture is scrapped, an angel gets its wings.
lingwendil is offline   Reply With Quote
Old 10/27/2017, 03:45 PM   #35
perkint
Registered Member
 
Join Date: Jan 2014
Posts: 775
Quote:
Originally Posted by lingwendil View Post
Maybe a bit off topic, but is there something similar to the MCP23017 that allows for analog inputs? It sure would be nice to have a little 16 channel analog read functionality with the ESP chips. I have a perverse desire to have each channel knob-adjustable for testing and possible large-scale and/or professional use (for example, over a working display tank at a storefront, ability to show differences in real time is easier with some knobs for adjustment)where simple dimming control is all you need, with individual channel adjustability for tuning color and PAR.
There are a few I2C ADC solutions including:
https://www.adafruit.com/product/1083

But, you could always just use an Arduino for that bit - probably cheaper

Tim


perkint is offline   Reply With Quote
Old 10/29/2017, 11:47 AM   #36
perkint
Registered Member
 
Join Date: Jan 2014
Posts: 775
Quote:
Originally Posted by thegasman2000 View Post
Tim if you could that would be awesome. I have a pastebin here with the cobbled ugly code I currently have.
https://pastebin.com/r9D3h6us
I have to admit, I haven't looked through your code other than to check the variables I'm playing with, but a simple way to do it:
Code:
  request = "/whiteLevel=255";
  if (request.startsWith("/whiteLevel=") != -1) {
    request = request.substring(12);
    whiteLevel = request.toInt();
    Serial.println("WHITE LEVEL SET ");
    Serial.println(whiteLevel);
  }
So you use substring to remove the command string "/whiteLevel=" leaving just the number in the String. Then you use toInt to convert what's left into an integer. If there is anything else left in the String rather than just the number, you can do substring(12,3) instead and move it into another String, then use toInt on the other String.

Make sense?

Tim


perkint is offline   Reply With Quote
Old 10/30/2017, 06:57 AM   #37
thegasman2000
Registered Member
 
thegasman2000's Avatar
 
Join Date: Dec 2005
Location: Pewsey, England
Posts: 86
Thanks Tim yes that makes sense and also works... My problem is that I have 2 channels Blue and White and the request is the same.

I'm using this
Code:
  if (request.startsWith("/LEDWHITE=") != -1) {
    request = request.substring(15,19);
    whiteLevel = request.toInt();
    Serial.print("WHITE LEVEL SET TO = ");
    Serial.println(whiteLevel);
  }

   if (request.startsWith("/LEDBLUE=") != -1) {
    request = request.substring(11,15);
    blueLevel = request.toInt();
    Serial.println("BLUE LEVEL SET TO = ");
    Serial.println(blueLevel);
  }
When I set the whites it's fine but when I set the blues I get the blue level not changing and the white level changing to the value, skewed via the difference in the url length.

I have stripped back the code to just figure it out. Here is the whole thing...

Code:
#include 
#include 
#include 
 
// Wifi Settings
const char* ssid = "PrettyFlyForAWifi";
const char* password = "reidbuck";
WiFiServer server(80);
 
// Time Settings
int timezone = 3;
int dst = 0;
 
int blueLevel = 1000;
int whiteLevel = 1000;
 
 
 
 
void setup() {
  Serial.begin(115200);
  delay(1);
 
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
 
  // Read the first line of the request
 
  
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Web Page Bit
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println();
 
  client.println("");
  client.println("");
  client.println("LED Control Module");
  client.println("");
  client.println("");
  client.println("
"); //uses IP/port of web page client.println("Set White Led Level:
"); client.println(""); client.println("
"); client.println("
"); client.println("
"); //uses IP/port of web page client.println("Set Blue Level:
"); client.println(""); client.println("
"); client.println("
"); client.println(""); if (request.startsWith("/LEDWHITE=") != -1) { request = request.substring(15,19); whiteLevel = request.toInt(); Serial.print("WHITE LEVEL SET TO = "); Serial.println(whiteLevel); Serial.println("Flush the variable Request"); request = "Flushed"; } if (request.startsWith("/LEDBLUE=") != -1) { request = request.substring(11,15); blueLevel = request.toInt(); Serial.println("BLUE LEVEL SET TO = "); Serial.println(blueLevel); Serial.println("Flush the variable Request"); request = "Flushed"; } Serial.println(whiteLevel); Serial.println(blueLevel); delay(1); Serial.println("Client disonnected"); Serial.println(""); }



__________________
The Google Fu is strong in this one.

Current Tank Info: 90 gallon sumped cube

Last edited by thegasman2000; 10/30/2017 at 07:49 AM.
thegasman2000 is offline   Reply With Quote
Old 10/30/2017, 08:16 AM   #38
perkint
Registered Member
 
Join Date: Jan 2014
Posts: 775
If you stick a Serial.print of request before you start processing it (ie between the last client.print and the if) what does it contain for each request (white & blue)?

Tim


perkint is offline   Reply With Quote
Old 10/30/2017, 08:31 AM   #39
thegasman2000
Registered Member
 
thegasman2000's Avatar
 
Join Date: Dec 2005
Location: Pewsey, England
Posts: 86
yeah I have been using them to track what happening.

Using this code:

Code:
  if (request.startsWith("/LEDWHITE=") != -1) {
    Serial.println(request);
    request = request.substring(15,19);
    Serial.println(request);
    whiteLevel = request.toInt();
    Serial.print("WHITE LEVEL SET TO = ");
    Serial.println(whiteLevel);
  }

   if (request.startsWith("/LEDBLUE=") != -1) {
    Serial.println(request);
    request = request.substring(11,15);
    Serial.println(request.substring(11,15));
    blueLevel = request.toInt();
    Serial.println("BLUE LEVEL SET TO = ");
    Serial.println(blueLevel);
  }
I added the values 1234 to the input for white and 2345 with blue...
With an output of:

new client
GET /?LEDWHITE=1234&submit=Send+White+LED+Level HTTP/1.1
GET /?LEDWHITE=1234&submit=Send+White+LED+Level HTTP/1.1
1234
WHITE LEVEL SET TO = 1234
1234

BLUE LEVEL SET TO =
0
Client disonnected



new client
GET /?LEDBLUE=2345&submit=Send+Blue+LED+Level HTTP/1.1
GET /?LEDBLUE=2345&submit=Send+Blue+LED+Level HTTP/1.1
345&
WHITE LEVEL SET TO = 345
345&

BLUE LEVEL SET TO =
0
Client disonnected


__________________
The Google Fu is strong in this one.

Current Tank Info: 90 gallon sumped cube
thegasman2000 is offline   Reply With Quote
Old 10/30/2017, 03:49 PM   #40
perkint
Registered Member
 
Join Date: Jan 2014
Posts: 775
Hang on! Two things jump out:
1. if (request.startsWith("/LEDWHITE=") != -1)
That conditional check (ie the bit in brackets that you checking for) is true (ie the code in curly brackets after the it gets executed) if request does not start with /LEDWHITE=
2. If that is a Serial.print of request then it actually begins with "GET /?LEDBLUE=" and has "&submit=Send+Blue+LED+Level HTTP/1.1" after the PWM value

So, unless I'm missing something change the string you check for to be "GET /?LEDWHITE=" and "GET /?LEDBLUE=" and replace "!= -1" to be "== true". And replace the numbers in the substring to the correct values - 14 for whites and 15 for blues isn't it? I think toInt will ignore the training text but I'm not sure -either try it or put a second value big enough for the PWM. Is it always 4 digits (eg 0000 or would that just be 0?)? If not you can use indexOf to find where &submit starts...

Tim


perkint is offline   Reply With Quote
Old 10/30/2017, 05:50 PM   #41
thegasman2000
Registered Member
 
thegasman2000's Avatar
 
Join Date: Dec 2005
Location: Pewsey, England
Posts: 86
Yeah == true would have been an awful lot easier but as they are different types its a no go... You did however get me googling the right things! I think (will test with the leds attached tomorrow) I have it working as intended. The code is

Code:
  String requestString = String(request);
  int indexPosition = requestString.indexOf('?');
  if (requestString.charAt(indexPosition + 1) == 'W') {
    requestString = requestString.substring(12, 16);
    whiteLevel = requestString.toInt();
    Serial.println("White LEVEL SET TO = ");
    Serial.println(whiteLevel);
    analogWrite(whiteLedPin, whiteLevel);

  }

  if (requestString.charAt(indexPosition + 1) == 'B') {
    requestString = requestString.substring(11, 15);
    blueLevel = requestString.toInt();
    Serial.println("BLUE LEVEL SET TO = ");
    Serial.println(blueLevel);
    analogWrite(blueLedPin, blueLevel);
  }
for anyone interested. I will test and if it works as intended I will link the whole thing once I have tidied it all up and commented it as required.

I also picked up a used MarsAqua LED 165w with the dimmer knobs on top. I will be adding that and will show the wiring when I have it buttoned up. Its different and requires a transistor on each channel but nice and easy to do


__________________
The Google Fu is strong in this one.

Current Tank Info: 90 gallon sumped cube

Last edited by thegasman2000; 10/30/2017 at 05:56 PM.
thegasman2000 is offline   Reply With Quote
Old 10/31/2017, 10:05 AM   #42
perkint
Registered Member
 
Join Date: Jan 2014
Posts: 775
Quote:
Originally Posted by thegasman2000 View Post
Yeah == true would have been an awful lot easier but as they are different types its a no go...
Shouldn't be - String.startsWith returns boolean true or false so you should have been able to do that. However...
Quote:
Originally Posted by thegasman2000 View Post
You did however get me googling the right things! I think (will test with the leds attached tomorrow) I have it working as intended. The code is

Code:
  String requestString = String(request);
  int indexPosition = requestString.indexOf('?');
  if (requestString.charAt(indexPosition + 1) == 'W') {
    requestString = requestString.substring(12, 16);
    whiteLevel = requestString.toInt();
    Serial.println("White LEVEL SET TO = ");
    Serial.println(whiteLevel);
    analogWrite(whiteLedPin, whiteLevel);

  }

  if (requestString.charAt(indexPosition + 1) == 'B') {
    requestString = requestString.substring(11, 15);
    blueLevel = requestString.toInt();
    Serial.println("BLUE LEVEL SET TO = ");
    Serial.println(blueLevel);
    analogWrite(blueLedPin, blueLevel);
  }
for anyone interested. I will test and if it works as intended I will link the whole thing once I have tidied it all up and commented it as required.

I also picked up a used MarsAqua LED 165w with the dimmer knobs on top. I will be adding that and will show the wiring when I have it buttoned up. Its different and requires a transistor on each channel but nice and easy to do
Looks good

Tim


perkint is offline   Reply With Quote
Old 11/01/2017, 05:11 PM   #43
thegasman2000
Registered Member
 
thegasman2000's Avatar
 
Join Date: Dec 2005
Location: Pewsey, England
Posts: 86
Ok so it works. I can set the intensity of either channel on the web interface and it sets the leds as expected. I thought this was a super simple thing to accomplish but the more you know...

I now need to add some scheduling to this. I am not using an RTC but getting the current time from the NTC servers. Anyone worked with time before? As its non linear I have no idea how to interact with it as a variable. if time == the time i need x to happen seems like a lot of if statements running every loop unnecessarily.

Current code is:

https://pastebin.com/b798nBc1


__________________
The Google Fu is strong in this one.

Current Tank Info: 90 gallon sumped cube
thegasman2000 is offline   Reply With Quote
Old 11/02/2017, 04:03 AM   #44
thegasman2000
Registered Member
 
thegasman2000's Avatar
 
Join Date: Dec 2005
Location: Pewsey, England
Posts: 86
Sorry meant NTP Server!


__________________
The Google Fu is strong in this one.

Current Tank Info: 90 gallon sumped cube
thegasman2000 is offline   Reply With Quote
Old 11/02/2017, 08:16 AM   #45
perkint
Registered Member
 
Join Date: Jan 2014
Posts: 775
Lots of ways to do it. One way would be to define an array of times and LED settings and loop thru that rather than lots of ifs. But you need to decide how you want to hold the time. You can just build it to a number made of the hours and minutes (eg 815 for 08:15, 2045 for 20:45) which is fairly simple and fairly readable. Or you can base it on number of minutes/seconds since midnight (a popular way of doing it).

In reality, loads of ways to do it that will work. Do you know what version of the time library you are using?

Tim


perkint is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -6. The time now is 11:35 PM.


TapaTalk Enabled

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Powered by Searchlight © 2017 Axivo Inc.
Use of this web site is subject to the terms and conditions described in the user agreement.
Reef CentralTM Reef Central, LLC. Copyright 1999-2014