Chinese LED hacking HELP!

Looks like a nice controller. Interface looks like the sort of thing I'd design! Not one that would please web designers, but one that is simple and works! But, that is just from a quick look at the page - not looked at the code...

Tim
 
Yeah after some (LOTS) CSS this could be a nice setup! I will dig through it and see if it a good base for what I want. Thanks for the link!

My plan is to use a esp8266 or the nicer esp32 to make the base controller. Perhaps with a slave esp on the lights and the main connected to a power bar. The esp32 would be better for this as it has bluetooth built in.

I wondered if you could emulate an apex and use their apps and web stuff...
 
Yeah after some (LOTS) CSS this could be a nice setup! I will dig through it and see if it a good base for what I want. Thanks for the link!

My plan is to use a esp8266 or the nicer esp32 to make the base controller. Perhaps with a slave esp on the lights and the main connected to a power bar. The esp32 would be better for this as it has bluetooth built in.

I wondered if you could emulate an apex and use their apps and web stuff...

Great work. If you don't mind sharing code, wiring, pics, that would be awesome.

Can you setup counter delays for the 24 hour cycle?

Or loop and constantly check time, if it hit your preset time, set
light level accordingly?

I have the ebay wifi unit and it sucks. I don't care for wifi, just ability to
program 24hrs. These wifi units go nuts and the lights behave on their own,
lights up, goes dark...
 
Yeah after some (LOTS) CSS this could be a nice setup! I will dig through it and see if it a good base for what I want. Thanks for the link!

My plan is to use a esp8266 or the nicer esp32 to make the base controller. Perhaps with a slave esp on the lights and the main connected to a power bar. The esp32 would be better for this as it has bluetooth built in.

I wondered if you could emulate an apex and use their apps and web stuff...

Looks pretty good to me for sure, but I'm braindead with code so I can't comment on how well put together it is :lol2:

I'm trying to learn as much as I can to put together a controller that will work for my pretty basic needs, although it's more complicated to implement them as I need them apparently.

If I knew what to do all at once, I would like the following features-

Cheap base hardware, I'm basing most of my efforts at the ~$5 Wemos Mini D1 type boards. Wifi onboard, and better processing power than the average Arduino specific boards in the same price range, while being compatible with the Arduino IDE. It also has native 10 bit PWM, which is nice if you only need 2-8 channels or so, which is realistically useful for the vast majority of applications.

Onboard Wifi to set and keep time. This would be a nice way to go, and I would preferably allow for a backup RTC. Simply turn on the controller, select the automatically generated access point it creates, log in to set your Wifi credentials, and go. Ideally it would then spool up an NTP request to set and sync the time, and would re-check every so often. It would be nice to replace the RTC with a bit of code!

2-8 channels of control, with 6 or more time slots. Ideally you would set these by logging into the unit via any internet browser, and set time slots and intensity via web form. It would be really nice to make this independent of apps and OS, so a simple interface such as those seen in old netgear routers would be awesome. Of course a pretty app can be figured out that will work too, but not really my priority.

Fan control seems a given, but having it track via temperature would be a nice feature, and is easy enough to do with a DS18B20 sensor. Alternatively, simply having the fan on/off at set times would work fine too.


All these features are implemented to some degree in many places and projects, it's just too much for me to figure out how to stitch them all together coherently enough to work in something. I'm a hardware guy, not a software guy! :worried2:
 
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
 
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.
 
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
 
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
 
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
 
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
 
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.

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.)

I have a pastebin here with the cobbled ugly code I currently have.
https://pastebin.com/r9D3h6us

:thumbsup:

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
 
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
 
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
 
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 <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
#include <time.h>
 
// 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("<HTML>");
  client.println("<HEAD>");
  client.println("<TITLE>LED Control Module</TITLE>");
  client.println("</HEAD>");
  client.println("<BODY>");
  client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page
  client.println("Set White Led Level: <INPUT TYPE=TEXT NAME='LEDWHITE' VALUE='' SIZE='25' MAXLENGTH='50'><BR>");
  client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Send White LED Level'>");
  client.println("</FORM>");
  client.println("<BR>");
  client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page
  client.println("Set Blue Level: <INPUT TYPE=NUMBER NAME='LEDBLUE' VALUE='' SIZE='25' MAXLENGTH='50'><BR>");
  client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Send Blue LED Level'>");
  client.println("</FORM>");
  client.println("<BR>");
  client.println("</BODY>");


  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("");

  
 
}
 
Last edited:
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
 
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
 
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
 
Back
Top