예제 #1
0
void SmartWifi::handleCycle(){
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillisReboot >= intervalReboot) {
    // save the last time you blinked the LED
      previousMillisReboot = currentMillis;
    ESP.restart();
  }
  if (setupMode){
    intervalReboot = 360000;
    server.handleClient();
  }else{
    //webSocketLoop(); 
  }
}
예제 #2
0
void loop() {
  client.loop();
  //start the OTA handler
  ArduinoOTA.handle();
  httpServer.handleClient();

  long now = millis();

  if(now - lastMsg > 1000) {
    lastMsg = now;

    if (!client.connected()) {
      reconnect();
    }

    /* Get a new sensor event */
    sensors_event_t bmpEvent;
    bmp.getEvent(&bmpEvent);

    if (bmpEvent.pressure)
    {
      bmp.getTemperature(&temp);
      float newPress = bmpEvent.pressure;
      float newTempF = convertToF(temp);

      if (checkBound(newTempF, tempF, diff)) {
        tempF = newTempF;
        Serial.print("New temperature:");
        Serial.println(String(tempF).c_str());
        client.publish(TOPIC_TEMP, String(tempF).c_str(), true);
      }

      if (checkBound(newPress, pressure, 3.00)) {
        pressure = newPress;
        Serial.print("New pressure:");
        Serial.println(String(pressure).c_str());
        client.publish(TOPIC_PRESS, String(pressure).c_str(), true);
      }
    } else {
        Serial.println("Sensor error");
    }
  }
}
예제 #3
0
void loop()
{
  server.handleClient();

  myBtn.read();

  if (myBtn.wasPressed())
  {
    if (state == ON)
    {
      state = OFF;
    }
    else
    {
      state = ON;
    }
  }
  digitalWrite(LED_PIN, state);

}
예제 #4
0
파일: Threm.cpp 프로젝트: ikutsin/espThrem
void Threm::loop() {

	// #ifdef DEBUG
	// DEBUG << "Threm::loop" << endl;
	// #endif

	_thremContext->beforeLoop();

	IThremPlugin*plugin;
	PluginMeta* meta;

	for (int i = 0; i < _plugins->size(); i++) {
		plugin = _plugins->get(i);
		meta = _pluginMeta->get(i);
		if (meta->isEnabled) {
			plugin->readData(_thremContext);
		}
	}
	yield();
	LinkedList < ThremNotification* >* notifications = _thremContext->getNotifications();

	for (int i = 0; i < _plugins->size(); i++) {
		plugin = _plugins->get(i);
		meta = _pluginMeta->get(i);
		if (meta->isEnabled) {
			for (int n = 0; n < notifications->size(); n++) {
				plugin->writeData(notifications->get(n));
			}
		}
	}
	yield();

	_thremContext->afterLoop();

	ESP8266WebServer* server = _thremContext->getServer();
	server->handleClient();
}
예제 #5
0
void loop() {
  if (safeMode) { // safeMode engaged, enter blocking loop wait for an OTA update
    int safeDelay=30000; // five minutes in 100ms counts
    while (safeDelay--) {
      ArduinoOTA.handle();
      delay(100);
    }
    ESP.reset(); // restart, try again
    delay(5000); // give esp time to reboot
  }

  if(wifiMulti.run() != WL_CONNECTED) { // reboot if wifi connection drops
      ESP.reset();
      delay(5000);
  }

  if (!mqtt.connected()) {
    mqttreconnect(); // check mqqt status
  }

  doTick();

  if (hasRSSI) doRSSI();
  if (hasTout) doTout();
  if (hasVout) doVout();
  if (hasIout) doIout();
  if (getRGB) doRGBout();
  if (hasSpeed) doSpeed();

  if ( (doUpdate) || (updateCnt>= 60 / ((updateRate * 20) / 1000) ) ) runUpdate(); // check for config update as requested or every 60 loops

  if (wsConcount>0) wsData();
  if (useMQTT) mqttData(); // regular update for non RGB controllers
  if (prtConfig) printConfig(); // config print was requested

  sprintf(str,"Sleeping in %u seconds.", (updateRate*20/1000));
  if ((!skipSleep) && (sleepEn)) {
    if (useMQTT) mqtt.publish(mqttpub, str);
  }

  int cnt = 30;
  if (updateRate>30) cnt=updateRate;
  while(cnt--) {
    ArduinoOTA.handle();
    if (useMQTT) mqtt.loop();

#ifndef _MINI
    httpd.handleClient();
#endif
    webSocket.loop();

    if (getTime) updateNTP(); // update time if requested by command
    if (scanI2C) i2c_scan();

    if (hasRGB) doRGB(); // rgb updates as fast as possible
    if (rgbTest) testRGB();

#ifndef _MINI

    if (doUpload) { // upload file to spiffs by command
      doUpload = false; fileSet = false;
      int stat = uploadFile(fileName, fileURL);
      sprintf(str, "Upload complete: %s %d bytes.",fileName,stat);
      if (useMQTT) mqtt.publish(mqttpub, str);
    }
#endif

    if (setPolo) {
      setPolo = false; // respond to an mqtt 'ping' of sorts
      if (useMQTT) mqtt.publish(mqttpub, "Polo");
    }

    if (doReset) { // reboot on command
      if (useMQTT) {
        mqtt.publish(mqttpub, "Rebooting!");
        mqtt.loop();
      }
      delay(50);
      ESP.reset();
      delay(5000); // allow time for reboot
    }

    if (!hasRGB) delay(20); // don't delay for rgb controller
  }

  if ((!skipSleep) && (sleepEn)) {
    if ((sleepPeriod<60) || (sleepPeriod>43200)) sleepPeriod=900; // prevent sleeping for less than 1 minute or more than 12 hours
    sprintf(myChr,"Back in %d minutes", sleepPeriod/60);
    if (useMQTT) {
      mqtt.publish(mqttpub, myChr);
      mqtt.loop();
    }

    ESP.deepSleep(1000000 * sleepPeriod, WAKE_RF_DEFAULT); // sleep for 15 min
    delay(5000); // give esp time to fall asleep

  }
  skipSleep = false;
  updateCnt++;
}
예제 #6
0
void loop() {
  HTTP.handleClient();
  delay(1);
}
예제 #7
0
void loop(void){
  // This seems to be necessary - I don't know the specifics of why quite yet.
  server.handleClient();
}
예제 #8
0
void WEBINTERFACE_CLASS::handleClient()
{
  server.handleClient();
}
예제 #9
0
void loop() {
	lux = lightMeter.readLightLevel();
	server.handleClient();
	delay(50);
}
예제 #10
0
void webServerLoop() {
  webServer.handleClient();
}
예제 #11
0
void Wifi::wifiLoop() {
    webSocket.loop();
    server.handleClient();
}
예제 #12
0
파일: src.cpp 프로젝트: RitterRBC/Arduino
void loop() { server.handleClient(); }
예제 #13
0
void handleClient()
{
    server.handleClient();
}