LYT8266 boot time

For problems with LYT/WiFi itself, NOT your project

LYT8266 boot time

Postby emigrating » Fri Sep 09, 2016 1:44 pm

Quick question as I'm still somewhat of an Arduino n00b :)

Is there a way to get these bulbs to output light (any light will do, although I am storing last used parameters on local filesystem)? I've tried moving things around, for example doing the LED stuff before anything else, but it still takes a good 10? seconds before we get output.
I'm unable to get anything over the serial interface on my bulbs so it's hard to debug what exactly is happening at any given time, but something seems to be eating cycles.

I also tried flashing the WebServer example, and while that is faster than my code, it still takes a few seconds (3 or so at a guess).

Ideally, I'd like to default the bulb to whatever state was last stored locally as soon as power is applied (within reason of the milliseconds it takes to run thru the bootloader and whatnot), so it can happen long before WiFi control is available etc.

Any ideas?
emigrating
 
Posts: 16
Joined: Thu Nov 26, 2015 9:27 am

Re: LYT8266 boot time

Postby pietromoscetta » Sun Sep 11, 2016 6:02 pm

Hi Arne,

if you want to have light as soon as you power on the LYT8266 you can add, for example, the following command into the setup() function after the vfESP8266HWInit() call:
void setup()
{
Serial.begin(115200);
Serial.println("");
delay(2000);
Serial.println("LYT8266");
Serial.printf("Sketch size: %u\n", ESP.getSketchSize());
Serial.printf("Free size: %u\n", ESP.getFreeSketchSpace());

myLYT8266Led.vfESP8266HWInit();
myLYT8266Led.vfSetWhiteValue(200);
......

In this example I set a value of 200 for the brightness but you can choose any values between 1 and 255.
You can also remove the delay(2000) row to save 2 more seconds.
If you already tried this please paste here you code so to have a look.

P.
pietromoscetta
Site Admin
 
Posts: 65
Joined: Tue Jun 30, 2015 3:03 pm

Re: LYT8266 boot time

Postby emigrating » Mon Sep 12, 2016 2:13 pm

Thanks, but this is pretty much what I had already done, although I use vfSwitchOn() rather than vfSetWhiteValue().

The problem seems to be that setup() is fully executed before vfESP8266 code is - even though it appears at the top of setup(). See the following code for a repro.

Code: Select all
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiUDP.h>
#include <LYT8266_WEB_OTA.h>
#include <LYT8266Led.h>
#include <FS.h>

const char *mySSID="Olofstuga";
const char *myPassword="3G#XM=9an#6{%!.5";

String hostName;
byte mac[6];
LYT8266Led LYT8266;
OTA_Setup(8080)
WiFiUDP myUDP;
unsigned int ui32Time;

void setup() {
  Serial.begin(115200);
  LYT8266.vfESP8266HWInit();
  LYT8266.vfSwitchOn();
  WiFi.begin(mySSID,myPassword);
}

void loop() {
  OTA_Process()
  LYT8266.vfLYT8266LedTask();
}


This executes in milliseconds. Bulb outputs light perhaps 200ms after power is supplied. This is similar to off-the-sheld LED bulbs from IKEA or whatever, not a problem.

However, change the above code to this;
Code: Select all
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiUDP.h>
#include <LYT8266_WEB_OTA.h>
#include <LYT8266Led.h>
#include <FS.h>

const char *mySSID="Olofstuga";
const char *myPassword="3G#XM=9an#6{%!.5";

String hostName;
byte mac[6];
LYT8266Led LYT8266;
OTA_Setup(8080)
WiFiUDP myUDP;
unsigned int ui32Time;

void setup() {
  Serial.begin(115200);
  LYT8266.vfESP8266HWInit();
  LYT8266.vfSwitchOn();
  WiFi.begin(mySSID,myPassword);

  ui32Time=millis();
  while ((WiFi.status()!=WL_CONNECTED)&&(millis()-ui32Time<10000))
  {
    delay(1000);
    Serial.print(".");
  }
  Serial.println("Connected");
}

void loop() {
  OTA_Process()
  LYT8266.vfLYT8266LedTask();
}


and you're looking at several seconds - all depending on how long it takes to actually complete the Wi-Fi connection.

Now, if we remove delay(1000); from the above, it still takes a few seconds to light up, problem is it never lights up fully, it just sits there and blinks at you forever.

I don't know enough about coding for the Arduino (or in this case the ESP8266 via Arduino) to say if there are race conditions present or what the actual issue is, but... I don't like it :) Basically, it renders the bulb "useless" (at least in certain situations) if the Wi-Fi network goes down (say emergency lighting - you don't want to wait 10+ seconds from pushing the button to the room lighting up if you just heard a loud noise outside the bedroom window in the middle of the night - and yes, normally this isn't an issue because you'll just say "House, turn on the light", but say the noise was an intruder cutting the power and the generator kicking in...).

If any of you fine souls out there could help me with a solution that allows light to flow less than a second after power-on while leaving all functionality intact I'd be forever grateful :D
emigrating
 
Posts: 16
Joined: Thu Nov 26, 2015 9:27 am

Re: LYT8266 boot time

Postby pietromoscetta » Mon Sep 12, 2016 2:38 pm

Hi Arne,

ok, now it is very clear.
It is very easy to solve your problem and you can do it in different ways.
First of all (if you have time you can open and study the Lyt8266Led library in your arduino folder) you need to consider that using our library all the operation on the LYT8266 are executed by calling continuously the vfLYT8266LedTask() function. When you call for example the vfSwitchOn() function this is only settings some values and activate some flags that will be processed with call to vfLYT8266LedTask().
As probably you already understood it is enough to call vfLYT8266LedTask() inside the while loop awaiting for connection and this will solve your problem.
Alternatively you can modify permanently the behavior of the bulb at power on and modify the Lyt8266Led.cpp source file changing the vfESP8266HWInit() in this way:

void LYT8266Led::vfESP8266HWInit(void)
{
pinMode(RED_PIN, OUTPUT); // Red
pinMode(GREEN_PIN, OUTPUT); // Green
pinMode(BLUE_PIN, OUTPUT); // Blue
pinMode(WHITE_PIN, OUTPUT); // White
pinMode(POWER_ENABLE_LED, OUTPUT); // Power Led Enable
analogWriteFreq(500);
analogWriteRange(255);
digitalWrite(RED_PIN, OFF);
digitalWrite(GREEN_PIN, OFF);
digitalWrite(BLUE_PIN, OFF);
digitalWrite(WHITE_PIN, OFF); --> change this row in: digitalWrite(WHITE_PIN, ON);
delay(500);
digitalWrite(POWER_ENABLE_LED, ON);
}


I hope it helps.

P.
pietromoscetta
Site Admin
 
Posts: 65
Joined: Tue Jun 30, 2015 3:03 pm

Re: LYT8266 boot time

Postby emigrating » Tue Sep 13, 2016 10:48 pm

Thanks, that works.
I could have swore this was one of the first things I tried though (after removing the 500ms delay to see if that would do anything). Oh well, it works now, so that's great.
emigrating
 
Posts: 16
Joined: Thu Nov 26, 2015 9:27 am


Return to Installation & Troubleshooting

Who is online

Users browsing this forum: No registered users and 0 guests

cron