Пример #1
1
void setup() {
  Serial.begin(115200);
  delay(10);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  Wire.begin(SDA, SCL); //sda,scl
  Serial.println("Sensor Test");
  if (!bmp.begin())
  {
    Serial.print("Ooops, no BMP180 detected ... Check your wiring or I2C ADDR!");
    while (1);
  }
  else {
    Serial.println("BMP180 ready.");
    delay(1000);
  }

  /* OTA code */
  ArduinoOTA.onStart([]() {
    Serial.println("Start");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });
  ArduinoOTA.begin();

  // Set up mDNS responder:
  // - first argument is the domain name, in this example
  //   the fully-qualified domain name is "esp8266.local"
  // - second argument is the IP address to advertise
  //   we send our IP address on the WiFi network
  if (!MDNS.begin(hostname, WiFi.localIP())) {
    Serial.println("Error setting up MDNS responder!");
    while(1) {
      delay(1000);
    }
  }
  Serial.print("mDNS responder started: ");
  Serial.print(hostname);
  Serial.println(".local");
  httpUpdater.setup(&httpServer);
  httpServer.begin();
  MDNS.addService("http", "tcp", 80);
}
Пример #2
0
void setup() {
  Serial.begin(115200);
  setup_wifi();
  pinMode(LED_PIN, OUTPUT);
  pinMode(SW_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(SW_PIN), handle_toggle_switch_interrupt, FALLING);
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}
Пример #3
0
void setup() {
  pinMode(BUILTIN_LED, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
  pinMode(16, OUTPUT);
  pinMode(5, INPUT);
  Serial.begin(115200);
  setup_wifi();
  delay(10000);
  client.setServer(mqtt_server, 2000);
  client.setCallback(callback);
}
Пример #4
0
void setup(void)
{
  Serial.begin(115200);

  setup_wifi();

  pinMode(BUILTIN_RELAY, OUTPUT);

  client.setServer(MQTT_BROKER, 1883);
  client.setCallback(mqtt_callback);
  // subscription to MQTT topics is performed in reconnect()

  display.begin(2 /* sda */, 4 /* scl */);
}
Пример #5
0
void app_main(void)
{
    nvs_flash_init();

    g_pot_event_group = xEventGroupCreate();
    g_wifi_event_group = xEventGroupCreate();

    setup_variables();
    setup_wifi();
    setup_gpios();

    printf("v3 size: %d\n", sizeof(struct uni_proto_v3));

    xTaskCreate(main_loop, "main_loop", 2048, NULL, 10, NULL);
    xTaskCreate(wifi_loop, "wifi_loop", 2048, NULL, 10, NULL);
//    xTaskCreate(test_loop, "test_loop", 2048, NULL, 10, NULL);

//    main_loop(NULL);
}
void hubless_mqtt_setup() {
    //load the configuration file and use configurations to connect to wifi
    if(!loadConfig()) {
        Serial.println("Failed to mount file system.");
        return;
    }

    //wifi shouldn't be connected yet
    connectedToWifi = 0;

    //set output pins
    pinMode(led, OUTPUT);
    pinMode(switchPin, OUTPUT);

    //set desired state based on reading the output pin
    if(digitalRead(switchPin) == HIGH) {
        strcpy(currentStateStr, "on");
        currentState = HIGH;
    }
    else {
        strcpy(currentStateStr, "off");
        currentState = LOW;
    }

    //start serial monitor output
    Serial.begin(115200);

    //connect to wifi
    setup_wifi();

    //set mqtt server
    client.setServer(mqtt_endpoint, mqtt_port);

    //set callback function
    client.setCallback(callback);
}