Esempio n. 1
0
NtpClient::NtpClient(String reqServer, int reqIntervalSeconds, NtpTimeResultDelegate delegateFunction /* = NULL */)
{
	// init timer but do not start, correct interval set later below.
	autoUpdateTimer.initializeMs(NTP_DEFAULT_QUERY_INTERVAL_SECONDS * 1000,
			TimerDelegate(&NtpClient::requestTime, this));

	timeoutTimer.initializeMs(NTP_RESPONSE_TIMEOUT_MS,
			TimerDelegate(&NtpClient::requestTime, this));


	this->server = reqServer;
	this->delegateCompleted = delegateFunction;
	if (!delegateFunction)
	{
		autoUpdateSystemClock = true;
	}

	if (reqIntervalSeconds == 0)
	{
		setAutoQuery(false);
	}
	else
	{
		setAutoQueryInterval(reqIntervalSeconds);
		setAutoQuery(true);
		requestTime();
	}
}
Esempio n. 2
0
File: MCP.cpp Progetto: Hukuma23/WS
void MCP::interruptHandler() {
	DEBUG4_PRINTLN("MCP.intH");
	//awakenByInterrupt = true;

	pin = MCP23017::getLastInterruptPin();
	uint8_t last_state = MCP23017::getLastInterruptPinValue();
	uint8_t act_state = MCP23017::digitalRead(pin);

	DEBUG4_PRINTF("push pin=%d state=%d. ", pin, act_state);

	String msg = "push pin= " + String(pin) + ", state= " + String(act_state);
	mqtt->publish("log_mcp_handler", OUT, msg);

	if (act_state == LOW) {
		timerBtnHandle.initializeMs(LONG_TIME, TimerDelegate(&MCP::longtimeHandler, this)).startOnce();
		turnSw(appSettings.getMInNumByPin(pin));

		//String strState = (turnSw(appSettings.getMInNumByPin(pin))?"ON":"OFF");
		//if (mqtt)
		//	mqtt->publish(appSettings.topMIN, appSettings.getMInNumByPin(pin)+1, OUT, strState);
	}
	else {
		attachInterrupt(appSettings.m_int, Delegate<void()>(&MCP::interruptCallback, this), FALLING);
		DEBUG4_PRINTLN();
	}

}
Esempio n. 3
0
void NtpClient::requestTime()
{
	if (!WifiStation.isConnected())
	{
		connectionTimer.initializeMs(1000, TimerDelegate(&NtpClient::requestTime, this)).startOnce();
		return;
	}

	struct ip_addr resolvedIp;
	int result = dns_gethostbyname(this->server.c_str(), &resolvedIp,
			staticDnsResponse, (void*) this);

	switch (result)
	{
	case ERR_OK:
		// Documentation says this will be the result if the string is already
		// an ip address in dotted decimal form or if the host is found in dns cache.
		// however I'm not sure if the dns cache is working since this never seems to
		// be called for a host lookup other than an ip address.
		// Doesn't really matter since the loockup will be fast anyways, the host
		// is most likely found in the dns cache of the next node the query is sent to.
		internalRequestTime(resolvedIp);
		break;
	case ERR_INPROGRESS:
		// currently finding ip, internalRequestTime() will be called when its found.
		//debugf("DNS IP lookup in progress.");
		break;
	default:
		debugf("DNS lookup error occurred.");
		break;
	}
}
void OpenHabMqttController::begin()
{
    checkTimer.initializeMs(
        1000,
        TimerDelegate(&OpenHabMqttController::checkConnection,
	              this)).start(true);
}
Esempio n. 5
0
void NtpClient::requestTime()
{
    if (!WifiStation.isConnected())
    {
        connectionTimer.initializeMs(1000, TimerDelegate(&NtpClient::requestTime, this)).startOnce();
        return;
    }
    if (serverAddress.isNull())
    {
        if (!resolveServer())
        {
            return;
        }
    }

//	connect to current active serverAddress, on NTP_PORT
    this->connect(serverAddress,NTP_PORT);

    uint8_t packet[NTP_PACKET_SIZE];

    // Setup the NTP request packet
    memset(packet, 0, NTP_PACKET_SIZE);

    // These are the only required values for a SNTP request. See page 14:
    // https://tools.ietf.org/html/rfc4330
    // However size of packet should still be 48 bytes.
    packet[0] = (NTP_VERSION << 3 | 0x03); // LI (0 = no warning), Protocol version (4), Client mode (3)
    packet[1] = 0;     	// Stratum, or type of clock, unspecified.

//	Send to server, serverAddress & port is set in connect
    NtpClient::send((char*) packet, NTP_PACKET_SIZE);
}
void HttpFirmwareUpdate::start()
{
	WDT.enable(false);
	spiffs_unmount();
	spiffs_config cfg = spiffs_get_storage_config();
	spiffs_format_internal(&cfg);
	pos = cfg.phys_addr;

	timer.initializeMs(500, TimerDelegate(&HttpFirmwareUpdate::onTimer, this)).start();
}
void irom _cRelay::_Off()
{
	if(_stat == _ON)
	{
		relay_timer.initializeMs(DELAY_RELAY_TIMER, TimerDelegate(&_cRelay::_tick_relay, this)).start();
		_wdgHw._startWdgCounter(ID_RELAY_TIMER);

		_stat = _OFF;

		_gpioDtcNull._conf(_INTERRUPT,_PULL_NONE,_OFF,_INTR_ANYEDGE);// DTC_MOVE (start)
	}
}
Esempio n. 8
0
void DS18S20::StartMeasure()
{
	if (!InProgress)
	{

		debugx("  DBG: DS1820 reading task start, try to read up to %d sensors",MAX_SENSORS);
		InProgress=true;
		ds.begin();
		ds.reset_search();
		DelaysTimer.initializeMs(150, TimerDelegate(&DS18S20::DoSearch, this)).start(false);
	}

}
Esempio n. 9
0
void MyDisplay::begin()
{
    byte error;

    Wire.lock();

#if DISPLAY_TYPE == DISPLAY_TYPE_SSD1306
    Wire.beginTransmission(0x3c);
    error = Wire.endTransmission();

    if (error == 0)
    {
        displayFound = TRUE;
        Debug.printf("Found OLED at %x\n", 0x3c);
        // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)`
        // initialize with the I2C addr 0x3D (for the 128x64)
        // bool:reset set to TRUE or FALSE depending on you display
        display.begin(SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS, FALSE);
        // display.begin(SSD1306_SWITCHCAPVCC);
        display.display();
    }
#elif DISPLAY_TYPE == DISPLAY_TYPE_20X4
    Wire.beginTransmission(I2C_LCD_ADDR);
    error = Wire.endTransmission();

    if (error == 0)
    {
        displayFound = TRUE;
        Debug.printf("Found LCD at %x\n", I2C_LCD_ADDR);
        lcd.begin(20, 4);
        lcd.setCursor(0, 0);
        lcd.print((char *)"MySensors gateway   ");
    }
    else
    {
        Debug.printf("LCD not found at %x\n", I2C_LCD_ADDR);
    }        
#else
    Debug.println("No display available");
    error = 0xff;
#endif

    Wire.unlock();

    if (displayFound)
    {
        displayTimer.initializeMs(1000, TimerDelegate(&MyDisplay::update, this)).start(true);
    }
}
Esempio n. 10
0
void wpsInit(WPSDelegate delegate) {
	connectDelegate = delegate;
	wpsRepeatCounter=10;

	debugf("WPS config started");

	// blink with LED to display active WPS pairing
	pinMode(LED_PIN, OUTPUT);
	blinkTimer = new Timer();
	blinkTimer->initializeMs(100, wpsBlinkIndicator).start();

	// start WPS pairing after 5s delay
	wpsTimer = new Timer();
	wpsTimer->initializeMs(5000,TimerDelegate(&wpsConnect)).startOnce();

}
Esempio n. 11
0
void DS18S20::StartReadNext()
{
   if (numberOf > numberOfread )
   {
	ds.reset();

	  uint64_t tmp=addresses[numberOfread];
	  for (uint8_t a=0;a<8;a++)
	  {
	    addr[7-a]=(uint8_t)tmp;
	    tmp=tmp>>8;
	  }

	  ds.select(addr);
	  ds.write(STARTCONVO, 1);        // start conversion, with parasite power on at the end

	  DelaysTimer.initializeMs(900, TimerDelegate(&DS18S20::DoMeasure, this)).start(false);
   }
Esempio n. 12
0
NtpClient::NtpClient(String reqServer, int reqIntervalSeconds, NtpTimeResultDelegate delegateFunction /* = NULL */)
{
    autoUpdateTimer.initializeMs(NTP_DEFAULT_AUTO_UPDATE_INTERVAL, TimerDelegate(&NtpClient::requestTime, this));
    this->server = reqServer;
    this->delegateCompleted = delegateFunction;
    if (!delegateFunction)
    {
        autoUpdateSystemClock = true;
    }

    if (reqIntervalSeconds == 0)
    {
        setAutoQuery(false);
    }
    else
    {
        setAutoQueryInterval(reqIntervalSeconds);
        setAutoQuery(true);
        requestTime();
    }

}
Esempio n. 13
0
// WPS Status callback
// 	- use callback to signal success
//  - restart up to 10 times
//  - slow blink (0,5Hz) if no success -> restart necessary
void wpsStatus(int status) {
	if (status == WPS_CB_ST_SUCCESS) {
		Serial.println("WPS config successful");
		wifi_wps_disable();
		WifiStation.connect();
		blinkTimer->stop();
		if (connectDelegate) connectDelegate();

	} else {
		wifi_wps_disable();
		wpsRepeatCounter--;
		if (wpsRepeatCounter>0) {
			Serial.print("WPS repeat");
			wifi_wps_enable(WPS_TYPE_PBC);
			wifi_set_wps_cb(&wpsStatus);
			wpsTimer->initializeMs(15000,TimerDelegate(&wpsStart)).startOnce();
		} else {
			wifi_wps_disable();
			blinkTimer->initializeMs(1000, wpsBlinkIndicator).start();
			wpsTimer->stop();
		}
	}
}
void AppWIFI::stopAp(int delay) {
	debugapp("AppWIFI::stopAp delay %i", delay);
	if(WifiAccessPoint.isEnabled()) {
		_timer.initializeMs(delay, TimerDelegate(&AppWIFI::stopAp, this)).startOnce();
	}
}
Esempio n. 15
0
void Switch::start()
{
	_refreshTimer.initializeMs(_refresh * 1000, TimerDelegate(&Switch::_timeout_action, this)).start(true);
}
Esempio n. 16
0
void Led::blinkSTART(uint16_t time)
{
	ledTimer.stop();
	ledTimer.initializeMs(time, TimerDelegate(&Led::toggle, this)).start();
}
Esempio n. 17
0
void StartOtaUpdate() 
{
    numOtaTrials++;
    otaStartTimer.initializeMs(50, TimerDelegate(otaUpdateHandler)).start(false);
}
Esempio n. 18
0
void rBootHttpUpdate::start() {
	timer.initializeMs(500, TimerDelegate(&rBootHttpUpdate::onTimer, this)).start();
}
Esempio n. 19
0
void BinInPollerClass::start()
{
	_refreshTimer.initializeMs(_refresh, TimerDelegate(&BinInPollerClass::_pollState, this)).start(true);
}
Esempio n. 20
0
void Led::flash(uint16_t time)
{
	on();
	ledTimer.stop();
	ledTimer.initializeMs(time, TimerDelegate(&Led::off, this)).startOnce();
}
Esempio n. 21
0
File: MCP.cpp Progetto: Hukuma23/WS
void MCP::start() {
	DEBUG4_PRINTLN("MCP::start");
	timer.initializeMs(appSettings.interval_mcp, TimerDelegate(&MCP::publish,this)).start();
}
Esempio n. 22
0
File: MCP.cpp Progetto: Hukuma23/WS
void MCP::startTimer() {
	DEBUG4_PRINTLN("MCP::startTimer");
	timer.initializeMs(appSettings.shift_mcp, TimerDelegate(&MCP::start, this)).startOnce();
};
Esempio n. 23
0
File: MCP.cpp Progetto: Hukuma23/WS
void MCP::interruptCallback() {
	DEBUG4_PRINT("MCP.intCB   ");
	detachInterrupt(appSettings.m_int);
	timerBtnHandle.initializeMs(DEBOUNCE_TIME, TimerDelegate(&MCP::interruptHandler, this)).startOnce();
}