123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include <ESP8266WiFi.h>
- #include <Wire.h>
- const char* ssid = "Hemnet3";
- const char* password = "";
- WiFiClient espClient;
- void connectWifi() {
- Serial.print("Connecting to ");
- Serial.println(ssid);
- // temporary fix until SDK 1.5.4 is used
- WiFi.persistent(false);
- WiFi.mode(WIFI_OFF);
- WiFi.mode(WIFI_STA);
- // temporary fix end
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.print(WiFi.status());
- Serial.print(".");
- }
-
- Serial.println("");
- Serial.print("Connected with IP: "),
- Serial.println(WiFi.localIP());
- }
- void setup() {
- Serial.begin(115200); //Opens USB-Serial connection for terminal
- delay(5000);
- Serial.print("Serial interface is ready\r\n");
- 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);
-
- }
|