Ejemplo n.º 1
0
void setup() {
  Serial.begin(9600);
  WiFiManager wifi;
  wifi.autoConnect("Light");
  brightness = 0;
  STATE = OFF;
  Serial.println("State: OFF");
  pinMode(LED_PIN, OUTPUT);
}
Ejemplo n.º 2
0
void setup()
{
  Serial.begin(115200);
  pinMode(BUTTON_PIN, INPUT);
  if (digitalRead(BUTTON_PIN) == 0)
  {
    Serial.println("Factory Reset");
  }

  WiFiManager wifi;
  wifi.autoConnect(DEVICE_NAME);

  if (!mdns.begin(DEVICE_NAME, WiFi.localIP()))
  {
    Serial.println("Error setting up MDNS responder!");
  }
  else
  {
    Serial.println("mDNS responder started");
  }

  // Start TCP (HTTP) server
  server.begin();
  Serial.println("TCP server started");

  Serial.println("Listening on port 8266");

  Serial.print("Sketch size: ");
  Serial.println(ESP.getSketchSize());
  Serial.print("Free size: ");
  Serial.println(ESP.getFreeSketchSpace());
  
  server.on("/", handle_root);
  server.on("/on", handle_on);
  server.on("/off", handle_off);

  httpUpdater.setup(&server);

  state = OFF;
  Serial.println("State: OFF");
  pinMode(LED_PIN, OUTPUT);
}
Ejemplo n.º 3
0
void setup()
{
  // Init serial
  Serial.begin(230400);
  Serial.println("Booting ESP8266 Htu21d wireless sensor");
  // Init wifi manager
  WiFiManager wifiManager;
  wifiManager.autoConnect("ESP8266 Sensor");
  // Init ArduinoOta
  // Port defaults to 8266
  // ArduinoOTA.setPort(8266);
  // Hostname defaults to esp8266-[ChipID]
  ArduinoOTA.setHostname("ESP8266FU");
  // No authentication by default
  // ArduinoOTA.setPassword((const char *)"123");
  ArduinoOTA.onStart([]() {
    Serial.println("*OTA: Start");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\n*OTA: End");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("*OTA: Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("*OTA: Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("*OTA: Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("*OTA: Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("*OTA: Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("*OTA: Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("*OTA: End Failed");
  });
  ArduinoOTA.begin();
  Serial.println("*OTA: Ready");
  Serial.print("*OTA: IP address: ");Serial.println(WiFi.localIP());
  // Init the humidity sensor
  while (!htu.begin()) {
    Serial.println("Couldn't find sensor!");
    delay(500);
  }
}
Ejemplo n.º 4
0
void setupWifi() {
    WiFiManager wifiManager;
    wifiManager.autoConnect(AP_NAME,AP_PASS);
    Serial.println("Wifi Manager Setup complete");
}
Ejemplo n.º 5
0
void setup()
{


#ifdef ESP8266_WiFi
	String mdns_id;

	mdns_id = eepromManager.fetchmDNSName();
	if(mdns_id.length()<=0)
		mdns_id = "ESP" + String(ESP.getChipId());


	// If we're going to set up WiFi, let's get to it
	WiFiManager wifiManager;
	wifiManager.setConfigPortalTimeout(5*60); // Time out after 5 minutes so that we can keep managing temps 
	wifiManager.setDebugOutput(false); // In case we have a serial connection to BrewPi
									   
	// The main purpose of this is to set a boolean value which will allow us to know we
	// just saved a new configuration (as opposed to rebooting normally)
	wifiManager.setSaveConfigCallback(saveConfigCallback);

	// The third parameter we're passing here (mdns_id.c_str()) is the default name that will appear on the form.
	// It's nice, but it means the user gets no actual prompt for what they're entering. 
	WiFiManagerParameter custom_mdns_name("mdns", "Device (mDNS) Name", mdns_id.c_str(), 20);
	wifiManager.addParameter(&custom_mdns_name);

	wifiManager.autoConnect(); // Launch captive portal with auto generated name ESP + ChipID

	// Alright. We're theoretically connected here (or we timed out).
	// If we connected, then let's save the mDNS name
	if (shouldSaveConfig) {
		// If the mDNS name is valid, save it.
		if (isValidmDNSName(custom_mdns_name.getValue())) {
			eepromManager.savemDNSName(custom_mdns_name.getValue());
		} else {
			// If the mDNS name is invalid, reset the WiFi configuration and restart the ESP8266
			WiFi.disconnect(true);
			delay(2000);
			handleReset();
		}
	}

	// Regardless of the above, we need to set the mDNS name and announce it
	if (!MDNS.begin(mdns_id.c_str())) {
		// TODO - Do something about it or log it or something
	}
#endif


#if BREWPI_BUZZER	
	buzzer.init();
	buzzer.beep(2, 500);
#endif	

	piLink.init();

#ifdef ESP8266_WiFi
	// If we're using WiFi, initialize the bridge
	server.begin();
	server.setNoDelay(true);
	// mDNS will stop responding after awhile unless we query the specific service we want
	MDNS.addService("brewpi", "tcp", 23);
	MDNS.addServiceTxt("brewpi", "tcp", "board", "ESP8266");
	MDNS.addServiceTxt("brewpi", "tcp", "branch", "legacy");
	MDNS.addServiceTxt("brewpi", "tcp", "version", VERSION_STRING);
	MDNS.addServiceTxt("brewpi", "tcp", "revision", FIRMWARE_REVISION);
#endif

    bool initialize = !eepromManager.hasSettings();
    if(initialize) {
        eepromManager.zapEeprom();  // Writes all the empty files to SPIFFS
        logInfo(INFO_EEPROM_INITIALIZED);
    }

	logDebug("started");
	tempControl.init();
	settingsManager.loadSettings();

#if BREWPI_SIMULATE
	simulator.step();
	// initialize the filters with the assigned initial temp value
	tempControl.beerSensor->init();
	tempControl.fridgeSensor->init();
#endif	

	display.init();
#ifdef ESP8266_WiFi
	display.printWiFi();  // Print the WiFi info (mDNS name & IP address)
	delay(8000);
	display.clear();
#endif
	display.printStationaryText();
	display.printState();

//	rotaryEncoder.init();

	logDebug("init complete");
}