12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #include <ESP8266WiFi.h>
- #include <Wire.h>
- #include "config.h"
- WiFiClient espClient;
- void connectWifi() {
- WiFi.disconnect(false);
- Serial.printf("Wi-Fi mode set to WIFI_STA: %s\n", WiFi.mode(WIFI_STA) ? "Ok" : "Failed!");
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- Serial.print("Connecting to ");Serial.println(WIFI_SSID);
-
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.print(WiFi.status());
- Serial.print(".\r\n");
- //WiFi.printDiag(Serial);
- }
-
- Serial.println("");
- Serial.print("Connected with IP: "),
- Serial.println(WiFi.localIP());
- Serial.printf("\n");
- }
- void setup() {
- Serial.println("setup()");
- Serial.begin(38400); //Opens USB-Serial connection for terminal
- delay(2000);
- Serial.println("Serial interface is ready");
- connectWifi();
- Wire.begin(4, 5); // sda on pin D2, scl on pin D1
- }
- void loop() {
- // put your main code here, to run repeatedly:
- byte error, address;
- int nDevices;
-
- Serial.print("WiFi heartbeat - ms since boot: ");
- Serial.print(millis());
- Serial.println();
- Serial.println("Scanning i2c devices... ");
- nDevices = 0;
- for(address = 1; address < 127; address++) {
- Wire.beginTransmission(address);
- error = Wire.endTransmission();
- if (error == 0) {
- Serial.print("I2C device found at address 0x");
- if (address<16)
- Serial.print("0");
- Serial.print(address,HEX);
- Serial.println(" !");
-
- nDevices++;
- }
- else if (error==4) {
- Serial.print("--Unknown error at address 0x");
- if (address<16)
- Serial.print("0");
- Serial.println(address,HEX);
- }
- }
- if (nDevices == 0)
- Serial.println("--No I2C devices found\n");
- else
- Serial.println("done\n");
-
- delay(1000);
-
- }
|