|
10/18/2017, 01:33 PM | #26 | |
Registered Member
Join Date: Dec 2005
Location: Pewsey, England
Posts: 91
|
Quote:
__________________
The Google Fu is strong in this one. Current Tank Info: 90 gallon sumped cube |
|
10/19/2017, 06:13 AM | #27 |
Registered Member
Join Date: Jan 2014
Location: Robin hood country, UK
Posts: 817
|
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 |
10/26/2017, 01:39 PM | #28 |
Registered Member
Join Date: Dec 2005
Location: Pewsey, England
Posts: 91
|
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 |
10/26/2017, 03:15 PM | #29 |
Registered Member
Join Date: Jan 2014
Location: Robin hood country, UK
Posts: 817
|
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 |
10/26/2017, 03:32 PM | #30 |
Registered Member
Join Date: Oct 2017
Posts: 10
|
lol china i dont support
|
10/26/2017, 04:03 PM | #31 | |
Registered Member
Join Date: Dec 2005
Location: Pewsey, England
Posts: 91
|
Quote:
https://pastebin.com/r9D3h6us
__________________
The Google Fu is strong in this one. Current Tank Info: 90 gallon sumped cube |
|
10/26/2017, 04:03 PM | #32 |
Registered Member
Join Date: Dec 2005
Location: Pewsey, England
Posts: 91
|
__________________
The Google Fu is strong in this one. Current Tank Info: 90 gallon sumped cube |
10/27/2017, 06:29 AM | #33 | |
Registered Member
Join Date: Jan 2014
Location: Robin hood country, UK
Posts: 817
|
Quote:
Will hopefully have a look tonight or over the weekend. Unless someone beats me to it! Tim |
|
10/27/2017, 07:39 AM | #34 | ||
Man who sold the world
Join Date: Oct 2004
Location: Oakley, behind enemy lines in communist occupied California.
Posts: 254
|
Quote:
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:
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. |
||
10/27/2017, 02:45 PM | #35 | |
Registered Member
Join Date: Jan 2014
Location: Robin hood country, UK
Posts: 817
|
Quote:
https://www.adafruit.com/product/1083 But, you could always just use an Arduino for that bit - probably cheaper Tim |
|
10/29/2017, 10:47 AM | #36 | |
Registered Member
Join Date: Jan 2014
Location: Robin hood country, UK
Posts: 817
|
Quote:
Code:
request = "/whiteLevel=255"; if (request.startsWith("/whiteLevel=") != -1) { request = request.substring(12); whiteLevel = request.toInt(); Serial.println("WHITE LEVEL SET "); Serial.println(whiteLevel); } Make sense? Tim |
|
10/30/2017, 05:57 AM | #37 |
Registered Member
Join Date: Dec 2005
Location: Pewsey, England
Posts: 91
|
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); } I have stripped back the code to just figure it out. Here is the whole thing... Code:
#include
__________________
The Google Fu is strong in this one. Current Tank Info: 90 gallon sumped cube Last edited by thegasman2000; 10/30/2017 at 06:49 AM. |
10/30/2017, 07:16 AM | #38 |
Registered Member
Join Date: Jan 2014
Location: Robin hood country, UK
Posts: 817
|
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 |
10/30/2017, 07:31 AM | #39 |
Registered Member
Join Date: Dec 2005
Location: Pewsey, England
Posts: 91
|
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); } 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 |
10/30/2017, 02:49 PM | #40 |
Registered Member
Join Date: Jan 2014
Location: Robin hood country, UK
Posts: 817
|
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 |
10/30/2017, 04:50 PM | #41 |
Registered Member
Join Date: Dec 2005
Location: Pewsey, England
Posts: 91
|
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); } 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 04:56 PM. |
10/31/2017, 09:05 AM | #42 | ||
Registered Member
Join Date: Jan 2014
Location: Robin hood country, UK
Posts: 817
|
Quote:
Quote:
Tim |
||
11/01/2017, 04:11 PM | #43 |
Registered Member
Join Date: Dec 2005
Location: Pewsey, England
Posts: 91
|
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 |
11/02/2017, 03:03 AM | #44 |
Registered Member
Join Date: Dec 2005
Location: Pewsey, England
Posts: 91
|
Sorry meant NTP Server!
__________________
The Google Fu is strong in this one. Current Tank Info: 90 gallon sumped cube |
11/02/2017, 07:16 AM | #45 |
Registered Member
Join Date: Jan 2014
Location: Robin hood country, UK
Posts: 817
|
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 |
|
|