├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── lib └── readme.txt ├── platformio.ini └── src ├── blink.cpp ├── esp32.cpp ├── esp8266.cpp ├── i2c_scanner.cpp ├── i2c_scanner.h ├── i2c_scanner_devices.cpp ├── main.cpp ├── one_wire.cpp ├── one_wire.h ├── wifi_connect.cpp └── wifi_scanner.cpp /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: PlatformIO CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | # os: [ubuntu-latest, macos-latest, windows-latest] 12 | os: [ubuntu-latest, macos-latest] 13 | example: [src] 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Cache pip 18 | uses: actions/cache@v2 19 | with: 20 | path: ~/.cache/pip 21 | key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} 22 | restore-keys: | 23 | ${{ runner.os }}-pip- 24 | - name: Cache PlatformIO 25 | uses: actions/cache@v2 26 | with: 27 | path: ~/.platformio 28 | key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} 29 | 30 | - name: Set up Python 31 | uses: actions/setup-python@v2 32 | 33 | - name: Install PlatformIO 34 | run: | 35 | python -m pip install --upgrade pip 36 | pip install --upgrade platformio 37 | pio update 38 | 39 | - name: Install library dependencies 40 | run: pio lib install 41 | 42 | - name: Run PlatformIO 43 | run: pio run 44 | env: 45 | PLATFORMIO_CI_SRC: ${{ matrix.example }} 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Platformio-related 2 | .pioenvs 3 | .piolibdeps 4 | .pio 5 | 6 | # Prerequisites 7 | *.d 8 | 9 | # Compiled Object files 10 | *.slo 11 | *.lo 12 | *.o 13 | *.obj 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Compiled Dynamic libraries 20 | *.so 21 | *.dylib 22 | *.dll 23 | 24 | # Fortran module files 25 | *.mod 26 | *.smod 27 | 28 | # Compiled Static libraries 29 | *.lai 30 | *.la 31 | *.a 32 | *.lib 33 | 34 | # Executables 35 | *.exe 36 | *.out 37 | *.app 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 John Romkey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP8266/ESP32 Diagnostic Utility 2 | 3 | [![PlatformIO CI](https://github.com/romkey/ESP-Diagnostic-Tool/actions/workflows/ci.yml/badge.svg)](https://github.com/romkey/ESP-Diagnostic-Tool/actions/workflows/ci.yml) 4 | 5 | This is a small set of diagnostics and debugging tools for the ESP8266. It's meant to help solve problems around Wifi and I2C. 6 | 7 | The utility includes Wifi and I2C scanners and can report basic information about the board you're using. 8 | 9 | 10 | ## Usage: 11 | 12 | The utility runs the serial port at 115,200 bps. You'll want to use some kind of terminal program to interact with it. 13 | 14 | The utility will display a menu when it starts: 15 | ``` 16 | Hello World 17 | 1. Show ESP information 18 | 2. Enter wifi credentials 19 | 3. Connect to wifi network 20 | 4. Current wifi info 21 | 5. Scan wifi networks 22 | 6. Scan I2C devices 23 | 0. Restart 24 | ``` 25 | 26 | ### 1 Show ESP Information 27 | 28 | This shows information about the ESP SDK and Arduino core that the utility was built with as well as information about the CPU it's running on. 29 | 30 | ``` 31 | SDK version 2.2.1(cfd48f3) 32 | Arduino Core version 2_4_1 33 | VCC 3013 34 | Chip ID 283132 35 | Flash Chip ID 1458208 36 | Flash Chip Speed 40000000 37 | Sketch Size 276032 38 | Free heap 43496 39 | Free sketch space 2867200 40 | Reset reason External System 41 | ``` 42 | 43 | ### 2 Enter Wifi credentials 44 | 45 | You'll enter an SSID and password, each up to 64 characters, ending with the RETURN key. You can use backspace or delete to go back a character. 46 | 47 | The SSID and password are not stored in flash and should not persist across reboots. 48 | 49 | ### 3 Connect to wifi network 50 | 51 | This item will attempt to connect the ESP to a wifi network or will disconnect from the current network. You must enter wifi credentials before you can connect. 52 | 53 | As it attempts to connect you should see wifi-related events. 54 | 55 | A connection attempt using a non-existent SSID should look like: 56 | 57 | ``` 58 | Connecting...............[wifi] 1, Disconnected - Status 6, Disconnected 59 | ............................................................................................................ 60 | ``` 61 | 62 | at this time you'll need to reset the CPU to get out of it. 63 | 64 | A connection attempt with an invalid passwords hould look like: 65 | ``` 66 | Connecting........[wifi] 2, AuthMode Change 67 | ............................[wifi] 1, Disconnected - Status 6, Disconnected 68 | ............................................................................ 69 | ``` 70 | 71 | at this time you'll need to reset the CPU to get out of it. 72 | 73 | A successful connection attempt should look like: 74 | 75 | ``` 76 | Connecting....[wifi] 2, AuthMode Change 77 | ............[wifi] 0, Connected 78 | .........[wifi] 3, Got IP 79 | 80 | WiFi connected 81 | ``` 82 | 83 | 84 | 85 | 86 | ### 4 Current wifi info 87 | 88 | When connect to a wifi network, this will show how the ESP was configured by DHCP and the RSSI for the wifi network. It will always show you the ESP's MAC address. 89 | 90 | ``` 91 | Connected 92 | Hostname ESP_0223FC 93 | MAC address 38:2B:78:02:23:FC 94 | IP address 10.0.1.206 95 | Subnet mask 255.255.255.0 96 | router IP 10.0.1.1 97 | first DNS server 10.0.1.1 98 | SSID YOUR WIFI NETWORK 99 | RSSi -51 100 | ``` 101 | 102 | 103 | ### 5 Scan wifi networks 104 | 105 | This will show you a list of wifi networks that the ESP can currently see. The list may seem very random. Only nearby access points will show up reliably. 106 | 107 | Remember that current ESPs are 2.4GHz devices. They support 802.11b/g/n but only the 2.4GHz band for n. They will never be able to see 5GHz 802.11a, 802.11n or 802.11ac networks. 108 | 109 | Scan network output will look like this: 110 | ``` 111 | About to scan wifi networks 112 | 113 | Wifi scan done 114 | 10 networks found 115 | SSID CHN RSS MAC address Encryption 116 | HOME-2001 1 -84 E8:3E:FC:23:23:23 WPA/WPA2/PSK 117 | you better know your dumplng 1 -58 44:D9:E7:23:23:23 CCMP 118 | CenturyLink2061 1 -92 58:8B:F3:23:23:23 WPA/WPA2/PSK 119 | NETGEAR69 3 -35 9C:3D:CF:23:23:23 CCMP 120 | HP-Print-28-Officejet Pro 8600 4 -87 A0:D3:C1:23:23:23 none 121 | extra cashew sauce 4 -66 8C:3B:AD:23:23:23 CCMP 122 | tell me about the dumpling 5 -53 80:2A:A8:23:23:23 CCMP 123 | xfinitywifi 6 -93 F6:AA:A0:23:23:23 none 124 | BAKINGINDAKITC 6 -92 EC:AA:A0:23:23:23 CCMP 125 | Internet of Dumplings 11 -52 88:1F:A1:23:23:23 WPA/WPA2/PSK 126 | ``` 127 | 128 | The MAC address is the MAC address of the access point. 129 | 130 | Encryption will be [WEP](https://en.wikipedia.org/wiki/Wired_Equivalent_Privacy), [TKIP](https://en.wikipedia.org/wiki/Temporal_Key_Integrity_Protocol), [CCMP](https://en.wikipedia.org/wiki/CCMP_(cryptography)), [WPA/WPA2/PSK](https://en.wikipedia.org/wiki/Wi-Fi_Protected_Access) or none. 131 | 132 | ### 6 I2C Scanner 133 | 134 | The I2C scanner probes each I2C address and reports which addresses respond. 135 | 136 | It also contains a list of known I2C devices by address and will report the known uses of each responding address. 137 | 138 | The list needs a lot of work and should eventually be stored in flash and not in the heap. 139 | 140 | An I2C scan with no I2C device should look like this: 141 | ``` 142 | Scanning... 143 | No I2C devices found 144 | ``` 145 | 146 | A successful I2C scan might look like this: 147 | ``` 148 | Scanning... 149 | I2C device found at address 0x18 150 | at 0x18 might be LIS3DH (3-axis accelerometer) 151 | at 0x18 might be LSM303 (Triple-axis Accelerometer+Magnetometer (Compass)) 152 | at 0x18 might be MCP9808 (temp sensor) 153 | I2C device found at address 0x39 154 | at 0x39 might be APDS-9960 (IR/Color/Proximity Sensor) 155 | at 0x39 might be TSL2561 (light sensor) 156 | at 0x39 might be VEML6070 (UV Index) 157 | I2C device found at address 0x53 158 | at 0x53 might be ADXL345 (3-axis accelerometer) 159 | at 0x53 might be MB85RC (Ferroelectric RAM) 160 | at 0x53 might be PCA9685 (16-channel PWM driver default address) 161 | I2C device found at address 0x5b 162 | at 0x5b might be CCS811 (VOC sensor) 163 | at 0x5b might be MPR121 (12-point capacitive touch sensor) 164 | at 0x5b might be PCA9685 (16-channel PWM driver default address) 165 | I2C device found at address 0x76 166 | at 0x76 might be BME280 (Temp/Barometric/Humidity) 167 | at 0x76 might be BMP280 (Temp/Barometric) 168 | at 0x76 might be HT16K33 (LED Matrix Driver) 169 | at 0x76 might be MS5607/MS5611 (Barometric Pressure) 170 | at 0x76 might be PCA9685 (16-channel PWM driver default address) 171 | at 0x76 might be TCA9548 (1-to-8 I2C Multiplexer) 172 | done 173 | ``` 174 | 175 | An I2C scan with malfunctioning hardware might look like this: 176 | ``` 177 | Scanning... 178 | Unknown error at address 0x01 179 | Unknown error at address 0x02 180 | Unknown error at address 0x03 181 | Unknown error at address 0x04 182 | ... 183 | ``` 184 | 185 | This means something is interfering with signalling on the I2C SDA and SDC lines. It's most likely an electrical or wiring problem but could possibly be a defective I2C device. 186 | 187 | The device list is generated by the web site https://i2cdevices.org/devices 188 | 189 | #### SPI Scanner 190 | 191 | There is no SPI scanner. SPI devices are individually selected - SPI doesn't have addresses. Which leaves us no way to scan for SPI devices. So, no SPI scanner; sorry. 192 | 193 | ### 0 Restart 194 | 195 | Resets the ESP. It should very quickly restart and present the menu again. 196 | 197 | ### H, ? and Newline 198 | 199 | These will all re-display the menu. 200 | 201 | ## Building and Installation 202 | 203 | You currently have to build the firmware yourself using [PlatformIO](https://platformio.org/). You can find installation instructions for it [on its site](https://platformio.org/get-started). 204 | 205 | 1. Clone the repository 206 | ``` 207 | git clone git@github.com:romkey/ESP-Diagnostic-Tool.git 208 | ``` 209 | 2. If the board you want to run on isn't currently in `platformio.ini`, add it. 210 | 211 | 3. Build it and upload it: 212 | ``` 213 | platformio run -e YOUR_BOARD_ID -t upload 214 | ``` 215 | 216 | Replace `YOUR_BOARD_ID` with the id for your board - for instance, Wemos D1 mini is listed in the shipping `platformio.ini` as `d1_mini`. 217 | 218 | 4. Run the serial monitor to interact with the utility. 219 | ``` 220 | platformio device monitor 221 | ``` 222 | 223 | If you missed the menu try typing `?` or `h` to see it. 224 | 225 | ## ESP32 Support 226 | 227 | The utility has very limited ESP32 support. It can't currently report Wifi events and can't give much information about the board. 228 | 229 | Bluetooth support looks problematic. The [Bluetooth library is so large](https://github.com/espressif/arduino-esp32/issues/1075) that it makes the firmware too big to load using the default flash partitioning scheme. You can work around this by [changing partitioning](https://desire.giesecke.tk/index.php/2018/01/30/change-partition-size/) but this is non-trivial. 230 | 231 | ## Roadmap 232 | 233 | 1. Add more I2C devices 234 | 235 | 2. Build under Arduino IDE 236 | 237 | 3. Add timeout to Wifi connect attempt 238 | 239 | 4. Support AP and STA_AP wifi modes 240 | 241 | 5. mDNS publish and resolve 242 | 243 | 6. Move I2C device names list to Flash storage. 244 | 245 | 7. Improve ESP32 support 246 | 247 | 8. ESP32 Bluetooth scanning? (not likely due to Bluetooth library size issues) 248 | 249 | 9. Add telnet/netcat-like functionality 250 | 251 | 10. Blink 252 | 253 | 11. Look at adding some kind of SSL testing 254 | 255 | ## License 256 | 257 | This code is published under the [MIT License](https://romkey.mit-license.org/). 258 | -------------------------------------------------------------------------------- /lib/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for the project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link to executable file. 4 | 5 | The source code of each library should be placed in separate directory, like 6 | "lib/private_lib/[here are source files]". 7 | 8 | For example, see how can be organized `Foo` and `Bar` libraries: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) http://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- readme.txt --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | Then in `src/main.c` you should use: 31 | 32 | #include 33 | #include 34 | 35 | // rest H/C/CPP code 36 | 37 | PlatformIO will find your libraries automatically, configure preprocessor's 38 | include paths and build them. 39 | 40 | More information about PlatformIO Library Dependency Finder 41 | - http://docs.platformio.org/page/librarymanager/ldf.html 42 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; http://docs.platformio.org/page/projectconf.html 10 | 11 | 12 | [env:d1_mini] 13 | platform = espressif8266 14 | board = d1_mini 15 | ;board = thingdev 16 | framework = arduino 17 | monitor_speed = 115200 18 | upload_speed = 115200 19 | lib_deps = OneWire, DallasTemperature 20 | 21 | ;[env:inkplate6] 22 | ;platform = espressif32 23 | ;board = inkplate 24 | ;framework = arduino 25 | ;monitor_speed = 115200 26 | ;upload_speed = 115200 27 | ;lib_deps = OneWire, DallasTemperature 28 | 29 | 30 | [env:thingdev] 31 | platform = espressif8266 32 | board = thingdev 33 | framework = arduino 34 | monitor_speed = 115200 35 | upload_speed = 115200 36 | lib_deps = OneWire, DallasTemperature 37 | 38 | [env:saola] 39 | platform = espressif32 40 | board = esp32-s2-saola-1 41 | framework = arduino 42 | monitor_speed = 115200 43 | upload_speed = 115200 44 | ;lib_deps = OneWire, DallasTemperature 45 | 46 | [env:thingplus] 47 | platform = espressif32 48 | board = esp32thing_plus 49 | framework = arduino 50 | monitor_speed = 115200 51 | upload_speed = 115200 52 | lib_deps = OneWire, DallasTemperature 53 | 54 | [env:lolin32] 55 | platform = espressif32 56 | board = lolin32 57 | ;board = thingdev 58 | framework = arduino 59 | monitor_speed = 115200 60 | upload_speed = 921600 61 | lib_deps = OneWire, DallasTemperature 62 | 63 | [env:tinypico] 64 | platform = espressif32 65 | board = tinypico 66 | framework = arduino 67 | monitor_speed = 115200 68 | upload_speed = 921600 69 | lib_deps = OneWire, DallasTemperature 70 | 71 | [env:esp32cam] 72 | platform = espressif32 73 | board = esp32cam 74 | ;board = thingdev 75 | framework = arduino 76 | monitor_speed = 115200 77 | upload_speed = 115200 78 | lib_deps = OneWire, DallasTemperature 79 | board_build.flash_mode = qio 80 | build_flags = 81 | -DCORE_DEBUG_LEVEL=0 82 | -DBOARD_HAS_PSRAM 83 | -mfix-esp32-psram-cache-issue 84 | board_build.partitions = huge_app.csv 85 | -------------------------------------------------------------------------------- /src/blink.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void blink_start(int pin) { 4 | pinMode(pin, OUTPUT); 5 | 6 | int current = LOW; 7 | 8 | while(1) { 9 | digitalWrite(pin, current); 10 | if(current == LOW) 11 | current = HIGH; 12 | else 13 | current = LOW; 14 | 15 | if(Serial.read() != -1) 16 | return; 17 | 18 | delay(500); 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/esp32.cpp: -------------------------------------------------------------------------------- 1 | #ifdef ESP32 2 | 3 | #include 4 | #include 5 | 6 | void esp_output() { 7 | Serial.println(); 8 | 9 | Serial.print("ESP-IDF version "); Serial.println(esp_get_idf_version()); 10 | Serial.print("Arduino Core version "); Serial.print(ESP_ARDUINO_VERSION_MAJOR); Serial.print("."); Serial.print(ESP_ARDUINO_VERSION_MINOR); Serial.print("."); Serial.println(ESP_ARDUINO_VERSION_PATCH); 11 | Serial.print("Flash Chip Speed "); Serial.println(ESP.getFlashChipSpeed()); 12 | Serial.print("Model "); Serial.print(ESP.getChipModel()); Serial.print(" revision "); Serial.println(ESP.getChipRevision()); 13 | Serial.print("Cores "); Serial.println(ESP.getChipCores()); 14 | Serial.print("PSRAM "); Serial.println(ESP.getPsramSize()); 15 | 16 | uint64_t mac_addr = ESP.getEfuseMac(); 17 | Serial.print("WIFI MAC address "); 18 | Serial.print(mac_addr & 0xFF, HEX); Serial.print(":"); 19 | Serial.print((mac_addr >> 8) & 0xFF, HEX); Serial.print(":"); 20 | Serial.print((mac_addr >> 16) & 0xFF, HEX); Serial.print(":"); 21 | Serial.print((mac_addr >> 24) & 0xFF, HEX); Serial.print(":"); 22 | Serial.print((mac_addr >> 32) & 0xFF, HEX); Serial.print(":"); 23 | Serial.println((mac_addr >> 40) & 0xFF, HEX); 24 | 25 | Serial.println(); 26 | Serial.println(); 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/esp8266.cpp: -------------------------------------------------------------------------------- 1 | #ifdef ESP8266 2 | 3 | #include 4 | #include 5 | 6 | extern "C" { 7 | #include 8 | }; 9 | 10 | #ifndef ESP32 11 | 12 | void esp_output() { 13 | Serial.println(); 14 | 15 | Serial.printf("SDK version %s\n", ESP.getSdkVersion()); 16 | #ifndef ESP32 17 | Serial.printf("Arduino Core version %s\n", ESP.getCoreVersion().c_str()); 18 | Serial.printf("VCC %d\n", ESP.getVcc()); 19 | Serial.printf("Chip ID %d\n", ESP.getChipId()); 20 | Serial.printf("Flash Chip ID %d\n", ESP.getFlashChipId()); 21 | #endif 22 | Serial.printf("Flash Chip Speed %d\n", ESP.getFlashChipSpeed()); 23 | #ifndef ESP32 24 | Serial.printf("Sketch Size %d\n", ESP.getSketchSize()); 25 | Serial.printf("Free heap %d\n", ESP.getFreeHeap()); 26 | Serial.printf("Free sketch space %d\n", ESP.getFreeSketchSpace()); 27 | Serial.printf("Reset reason %s\n", ESP.getResetReason().c_str()); 28 | #endif 29 | 30 | Serial.printf("Maximum TCP connections %d\n", MEMP_NUM_TCP_PCB); 31 | 32 | Serial.println(); 33 | Serial.println(); 34 | } 35 | 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/i2c_scanner.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "i2c_scanner.h" 5 | 6 | void i2c_begin() { 7 | Wire.begin(); 8 | } 9 | 10 | byte i2c_try_address(byte address) { 11 | Wire.beginTransmission(address); 12 | return Wire.endTransmission(); 13 | } 14 | 15 | void i2c_identify(byte); 16 | 17 | void i2c_scan() { 18 | byte error, address; 19 | int nDevices; 20 | 21 | Serial.println("Scanning..."); 22 | 23 | nDevices = 0; 24 | for(address = 1; address < 127; address++ ) { 25 | error = i2c_try_address(address); 26 | if(error == 0) { 27 | Serial.printf("I2C device found at address 0x%0x\n", address); 28 | i2c_identify(address); 29 | nDevices++; 30 | } else if(error==4) { 31 | Serial.printf("Unknown error at address 0x%0x\n", address); 32 | } 33 | } 34 | 35 | if(nDevices == 0) 36 | Serial.println("No I2C devices found\n"); 37 | else 38 | Serial.println("done\n"); 39 | } 40 | 41 | 42 | void i2c_identify(byte address) { 43 | for(int i = 0; i < i2c_scanner_known_devices_length; i++) { 44 | #if 0 45 | Serial.printf(" checking %d %s has %d addresses\n", i, i2c_scanner_known_devices[i].name, strlen((char *)i2c_scanner_known_devices[i].addrs)); 46 | Serial.printf(" want to match %02x\n", (int)address); 47 | #endif 48 | 49 | int j = 0; 50 | while(1) { 51 | #if 0 52 | Serial.printf(" checking char index %d is %02x\n", j, (int)i2c_scanner_known_devices[i].addrs[j]); 53 | #endif 54 | 55 | if(i2c_scanner_known_devices[i].addrs[j] == '\0') 56 | break; 57 | 58 | if(i2c_scanner_known_devices[i].addrs[j] == address) { 59 | Serial.printf(" at 0x%0x might be %s (%s)\n", address, i2c_scanner_known_devices[i].name, i2c_scanner_known_devices[i].function); 60 | break; 61 | } 62 | 63 | j++; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/i2c_scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /* i2c_device struct consists of a pointer to a name, a pointer 6 | * to a char* describing the function of the device, and a null 7 | * terminated byte array of addresses that the device responds to. 8 | */ 9 | typedef struct i2c_device { 10 | const char* name; 11 | const char* function; 12 | const byte *addrs; 13 | } i2c_device_t; 14 | 15 | extern i2c_device_t i2c_scanner_known_devices[]; 16 | extern int i2c_scanner_known_devices_length; 17 | -------------------------------------------------------------------------------- /src/i2c_scanner_devices.cpp: -------------------------------------------------------------------------------- 1 | #include "i2c_scanner.h" 2 | 3 | /* 4 | * This file is automatically generated by https://i2cdevices.org/ 5 | * 6 | * Generated 2022-01-13 04:54:03 +0000 7 | * 8 | * It's intended to be used by the ESP diagnostic tool at 9 | * https://github.com/romkey/ESP-Diagnostic-Tool 10 | * 11 | * To update the known device list in the diagnostic tool, 12 | * generate a new version of this file, copy it to the src 13 | * directory and rebuild the tool. 14 | * 15 | * The MIT License (MIT) 16 | * Copyright © 2022 John Romkey 17 | * 18 | * Permission is hereby granted, free of charge, to any person 19 | * obtaining a copy of this software and associated documentation 20 | * files (the “Software”), to deal in the Software without 21 | * restriction, including without limitation the rights to use, copy, 22 | * modify, merge, publish, distribute, sublicense, and/or sell copies 23 | * of the Software, and to permit persons to whom the Software is 24 | * furnished to do so, subject to the following conditions: The above 25 | * copyright notice and this permission notice shall be included in 26 | * all copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, 29 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 31 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 32 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 33 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 35 | * SOFTWARE. 36 | */ 37 | 38 | i2c_device_t i2c_scanner_known_devices[] = { 39 | { "", "Qwiic EEPROM - 512Kbit - 64KB", (const byte *)"\x57\x55\x54\x51\x56\x52\x53\x50" }, 40 | { "AD5243", "Dual, 256-Position, I2 C-Compatible Digital Potentiometer", (const byte *)"\x2f" }, 41 | { "AD5248", "Dual, 256-Position, I2 C-Compatible Digital Potentiometer", (const byte *)"\x2d\x2e\x2c\x2f" }, 42 | { "AD5251", "Dual 64-Position I2 C Nonvolatile Memory Digital Potentiometers", (const byte *)"\x2d\x2e\x2c\x2f" }, 43 | { "AD5252", "Dual 256-Position I2C Nonvolatile Memory Digital Potentiometers", (const byte *)"\x2d\x2e\x2c\x2f" }, 44 | { "ADS1115", "4-channel 16-bit ADC", (const byte *)"\x4b\x4a\x49\x48" }, 45 | { "ADS7828", "12-Bit, 8-Channel Sampling ANALOG-TO-DIGITAL CONVERTER", (const byte *)"\x4b\x4a\x49\x48" }, 46 | { "ADXL345", "3-axis accelerometer", (const byte *)"\x1d\x53" }, 47 | { "AHT10", "ASAIR Humidity and Temperature sensor", (const byte *)"\x38" }, 48 | { "AK8975", "3-axis magnetometer", (const byte *)"\x0f\x0e\x0c\x0d" }, 49 | { "AM2315", "Humidity/Temp sensor", (const byte *)"\x5c" }, 50 | { "AMG8833", "IR Thermal Camera Breakout", (const byte *)"\x69\x68" }, 51 | { "APDS-9250", "Digital RGB, IR and Ambient Light Sensor", (const byte *)"\x52" }, 52 | { "APDS-9960", "IR/Color/Proximity Sensor", (const byte *)"\x39" }, 53 | { "AS7262", "6-channel visible spectral_ID device with electronic shutter and smart interface", (const byte *)"\x49" }, 54 | { "ATECC508A", "Crypto Element", (const byte *)"\x60" }, 55 | { "ATECC608A", "Microchip CryptoAuthentication™ Device", (const byte *)"\x60" }, 56 | { "BMA150", "Digital triaxial acceleration sensor", (const byte *)"\x38" }, 57 | { "BMA180", "Accelerometer", (const byte *)"\x77" }, 58 | { "BME280", "Temp/Barometric/Humidity", (const byte *)"\x77\x76" }, 59 | { "BME680", "Low power gas, pressure, temperature & humidity sensor", (const byte *)"\x77\x76" }, 60 | { "BME688", "Digital low power gas, pressure, temperature and humidity sensor with AI", (const byte *)"\x77\x76" }, 61 | { "BMP085", "Temp/Barometric", (const byte *)"\x77" }, 62 | { "BMP180", "Temp/Barometric", (const byte *)"\x77" }, 63 | { "BMP280", "Temp/Barometric", (const byte *)"\x77\x76" }, 64 | { "BNO055", "Absolute Orientation Sensor", (const byte *)"\x28\x29" }, 65 | { "CAP1188", "8-channel Capacitive Touch", (const byte *)"\x2b\x2d\x2c\x28\x2a\x29" }, 66 | { "CAT5171", "256‐position I2C Compatible Digital Potentiometer ", (const byte *)"\x2d\x2c" }, 67 | { "CCS811", "Volatile organics (VOC) and equivalent CO2 (eCO2) sensor", (const byte *)"\x5b\x5a" }, 68 | { "Chirp!", "Water sensor", (const byte *)"\x20" }, 69 | { "COM-15093", "SparkFun Qwiic Single Relay", (const byte *)"\x19\x18" }, 70 | { "DRV2605", "Haptic Motor Driver", (const byte *)"\x5a" }, 71 | { "DS1307", "64 x 8 Serial Real-Time Clock", (const byte *)"\x68" }, 72 | { "DS3231", "Extremely Accurate RTC/TCXO/Crystal", (const byte *)"\x68" }, 73 | { "FT6x06", "Capacitive Touch Driver", (const byte *)"\x38" }, 74 | { "FXAS21002", "3-axis gyroscope", (const byte *)"\x21\x20" }, 75 | { "FXOS8700", "6-axis sensor with integrated linear accelerometer and magnetometer", (const byte *)"\x1d\x1f\x1e\x1c" }, 76 | { "HDC1008", "Low Power, High Accuracy Digital Humidity Sensor with Temperature Sensor", (const byte *)"\x43\x42" }, 77 | { "HIH6130", "HumidIcon", (const byte *)"\x27" }, 78 | { "HMC5883", "3-Axis Digital Compass/Magnetometer IC", (const byte *)"\x1e" }, 79 | { "HT16K33", "LED Matrix Driver", (const byte *)"\x73\x75\x72\x71\x77\x70\x76\x74" }, 80 | { "HTS221", "Capacitive digital sensor for relative humidity and temperature", (const byte *)"\x5f" }, 81 | { "HTU21D-F", "Humidity/Temp Sensor", (const byte *)"\x40" }, 82 | { "ICM-20948", " 9-Axis Motion Tracking device", (const byte *)"\x69\x68" }, 83 | { "INA219", "26V Bi-Directional High-Side Current/Power/Voltage Monitor", (const byte *)"\x4e\x43\x41\x46\x47\x4f\x42\x40\x4b\x45\x4d\x4a\x4c\x44\x49\x48" }, 84 | { "INA260", "Precision Digital Current and Power Monitor With Low-Drift, Precision Integrated Shunt", (const byte *)"\x4e\x43\x41\x46\x47\x4f\x42\x40\x4b\x45\x4d\x4a\x4c\x44\x49\x48" }, 85 | { "IS31FL3731", "144-LED Audio Modulated Matrix LED Driver (CharliePlex)", (const byte *)"\x77\x66" }, 86 | { "ISL29125", "Digital Red, Green and Blue Color Light Sensor with IR Blocking Filter", (const byte *)"\x44" }, 87 | { "IST-8310", "Three-axis Magnetometer", (const byte *)"\x0e" }, 88 | { "ITG3200", "Gyro", (const byte *)"\x69\x68" }, 89 | { "L3GD20H", "gyroscope", (const byte *)"\x6b\x6a" }, 90 | { "LIS3DH", "3-axis accelerometer", (const byte *)"\x19\x18" }, 91 | { "LPS22HB", "MEMS nano pressure sensor", (const byte *)"\x2e" }, 92 | { "LSM303", "Triple-axis Accelerometer+Magnetometer (Compass)", (const byte *)"\x19\x1e" }, 93 | { "LSM303", "Triple-axis Accelerometer+Magnetometer (Compass)", (const byte *)"\x18\x1e" }, 94 | { "MA12070P", "Merus Multi level Class D Interated amplifier ", (const byte *)"\x23\x22\x21\x20" }, 95 | { "MAG3110", "3-Axis Magnetometer", (const byte *)"\x0e" }, 96 | { "MAX30101", "High-Sensitivity Pulse Oximeter and Heart-Rate Sensor for Wearable Health", (const byte *)"\x55" }, 97 | { "MAX3010x", "Pulse & Oximetry sensor", (const byte *)"\x57" }, 98 | { "MAX44009", "Ambient Light Sensor with ADC", (const byte *)"\x4b\x4a" }, 99 | { "MB85RC", "Ferroelectric RAM", (const byte *)"\x57\x55\x54\x51\x56\x52\x53\x50" }, 100 | { "MCP23008", "8-Bit I/O Expander with Serial Interface I2C GPIO expander", (const byte *)"\x24\x26\x23\x22\x27\x25\x21\x20" }, 101 | { "MCP23017", "I2C GPIO expander", (const byte *)"\x24\x26\x23\x22\x27\x25\x21\x20" }, 102 | { "MCP4725A0", "12-bit DAC", (const byte *)"\x61\x60" }, 103 | { "MCP4725A1", "12-Bit Digital-to-Analog Converter with EEPROM Memory", (const byte *)"\x65\x63\x61\x62\x67\x66\x64\x60" }, 104 | { "MCP4725A2", "12-Bit Digital-to-Analog Converter with EEPROM Memory", (const byte *)"\x65\x64" }, 105 | { "MCP4725A3", "12-Bit Digital-to-Analog Converter with EEPROM Memory", (const byte *)"\x67\x66" }, 106 | { "MCP7940N", "Battery-Backed I2C Real-Time Clock/Calendar with SRAM", (const byte *)"\x6f" }, 107 | { "MCP9808", "±0.5°C Maximum Accuracy Digital Temperature Sensor", (const byte *)"\x1d\x1f\x1a\x1b\x19\x18\x1e\x1c" }, 108 | { "MLX90614", "IR temperature sensor", (const byte *)"\x5a" }, 109 | { "MLX90640", "Far infrared thermal sensor array (32x24 RES)", (const byte *)"\x33" }, 110 | { "MMA845x", "3-axis, 14-bit/8-bit digital accelerometer", (const byte *)"\x1d\x1c" }, 111 | { "MPL115A2", "Miniature I2C digital barometer, 50 to 115 kPa", (const byte *)"\x60" }, 112 | { "MPL3115A2", "Barometric Pressure", (const byte *)"\x60" }, 113 | { "MPR121", "12-point capacitive touch sensor", (const byte *)"\x5c\x5b\x5a\x5d" }, 114 | { "MPU6050", "Six-Axis (Gyro + Accelerometer) MEMS MotionTracking™ Devices", (const byte *)"\x69\x68" }, 115 | { "MPU-9250", "9-DoF IMU Gyroscope, Accelerometer and Magnetometer", (const byte *)"\x69\x68" }, 116 | { "MS5607", "Barometric Pressure", (const byte *)"\x77\x76" }, 117 | { "MS5611", "Barometric Pressure", (const byte *)"\x77\x76" }, 118 | { "NE5751", "Audio processor for IV communication", (const byte *)"\x41\x40" }, 119 | { "Nunchuck controller", "Nintendo", (const byte *)"\x52" }, 120 | { "PCA1070", "Multistandard programmable analog CMOS speech transmission IC", (const byte *)"\x22" }, 121 | { "PCA9685", "16-channel PWM driver default address", (const byte *)"\x57\x6d\x69\x6e\x55\x73\x4e\x79\x65\x5c\x5b\x75\x54\x72\x71\x63\x77\x43\x51\x56\x61\x41\x46\x47\x4f\x42\x40\x7f\x4b\x62\x45\x6b\x6f\x67\x6c\x70\x66\x64\x7d\x7c\x4d\x6a\x4a\x7b\x4c\x44\x52\x53\x78\x59\x5a\x58\x5d\x7a\x60\x68\x76\x5e\x50\x49\x74\x48\x5f\x7e" }, 122 | { "PCD3311C", "DTMF/modem/musical tone generator", (const byte *)"\x24\x25" }, 123 | { "PCD3312C", "DTMF/modem/musical-tone generator", (const byte *)"\x24\x25" }, 124 | { "PCF8523", "RTC", (const byte *)"\x68" }, 125 | { "PCF8569", "LCD column driver for dot matrix displays ", (const byte *)"\x3b\x3c" }, 126 | { "PCF8573", "Clock/calendar with Power Fail Detector", (const byte *)"\x69\x6b\x6a\x68" }, 127 | { "PCF8574", "Remote 8-Bit I/O Expander", (const byte *)"\x4e\x43\x41\x46\x47\x4f\x42\x40\x4b\x45\x4d\x4a\x4c\x44\x49\x48" }, 128 | { "PCF8574AP", "I²C-bus to parallel port expander", (const byte *)"\x3b\x39\x3c\x38\x3e\x3f\x3a\x3d" }, 129 | { "PCF8577C", "32/64-segment LCD display driver", (const byte *)"\x3a" }, 130 | { "PCF8578", "Row/column LCD dot matrix driver/display ", (const byte *)"\x3c\x3d" }, 131 | { "PMSA003I", "Digital universal partical concentration sensor", (const byte *)"\x12" }, 132 | { "PN532", "NFC/RFID reader", (const byte *)"\x48" }, 133 | { "SAA1064", "4-digit LED driver", (const byte *)"\x3b\x39\x38\x3a" }, 134 | { "SAA2502", "MPEG audio source decoder", (const byte *)"\x30\x31" }, 135 | { "SAA4700", "VPS Dataline Processor", (const byte *)"\x23\x21" }, 136 | { "SAA5243P/E", "Computer controlled teletext circuit ", (const byte *)"\x11" }, 137 | { "SAA5243P/H", "Computer controlled teletext circuit ", (const byte *)"\x11" }, 138 | { "SAA5243P/K", "Computer controlled teletext circuit ", (const byte *)"\x11" }, 139 | { "SAA5243P/L", "Computer controlled teletext circuit ", (const byte *)"\x11" }, 140 | { "SAA5246", "Integrated VIP and teletext", (const byte *)"\x11" }, 141 | { "SAB3035", "Digital tuning circuit for computer-controlled TV ", (const byte *)"\x63\x61\x62\x60" }, 142 | { "SAB3037", "Digital tuning circuit for computer-controlled TV", (const byte *)"\x63\x61\x62\x60" }, 143 | { "SCD40", "CO2 sensor - 2000ppm", (const byte *)"\x62" }, 144 | { "SCD40-D-R2", "Miniaturized CO2 Sensor", (const byte *)"\x62" }, 145 | { "SCD41", "CO2 sensor", (const byte *)"\x62" }, 146 | { "SEN-15892", "Zio Qwiic Loudness Sensor", (const byte *)"\x38" }, 147 | { "SEN-17374", "Sparkfun EKMC4607112K PIR", (const byte *)"\x12\x13" }, 148 | { "SGP30", "Gas Sensor", (const byte *)"\x58" }, 149 | { "SH1106", "132 X 64 Dot Matrix OLED/PLED Preliminary Segment/Common Driver with Controller", (const byte *)"\x3c\x3d" }, 150 | { "SHT31", "Humidity/Temp sensor", (const byte *)"\x45\x44" }, 151 | { "SHTC3", "Humidity & Temperature Sensor", (const byte *)"\x70" }, 152 | { "SI1132", "UV Index and Ambient Light Sensor", (const byte *)"\x60" }, 153 | { "SI1133", "UV Index and Ambient Light Sensor", (const byte *)"\x55\x52" }, 154 | { "Si1145", "Proximity/UV/Ambient Light Sensor IC With I2C Interface", (const byte *)"\x60" }, 155 | { "Si4713", "FM Radio Transmitter with Receive Power Scan", (const byte *)"\x63\x11" }, 156 | { "Si5351A", "Clock Generator", (const byte *)"\x61\x60" }, 157 | { "Si7021", "Humidity/Temp sensor", (const byte *)"\x40" }, 158 | { "SPS30", "Particulate Matter Sensor for Air Quality Monitoring and Control", (const byte *)"\x69" }, 159 | { "SSD1305", "132 x 64 Dot Matrix OLED/PLED Segment/Common Driver with Controller", (const byte *)"\x3c\x3d" }, 160 | { "SSD1306", "128 x 64 Dot Matrix Monochrome OLED/PLED Segment/Common Driver with Controller ", (const byte *)"\x3c\x3d" }, 161 | { "STMPE610", "Resistive Touch controller", (const byte *)"\x41\x44" }, 162 | { "STMPE811", "Resistive touchscreen controller", (const byte *)"\x41\x44" }, 163 | { "TCA9548", "1-to-8 I2C Multiplexer", (const byte *)"\x73\x75\x72\x71\x77\x70\x76\x74" }, 164 | { "TCA9554", "4 Low Voltage 8-Bit I 2C and SMBus Low-Power I/O Expander With Interrupt Output and Configuration Registers", (const byte *)"\x24\x26\x23\x22\x27\x25\x21\x20" }, 165 | { "TCS34725", "color sensor", (const byte *)"\x29" }, 166 | { "TDA4670", "Picture signal improvement circuit", (const byte *)"\x44" }, 167 | { "TDA4671", "Picture signal improvement circuit", (const byte *)"\x44" }, 168 | { "TDA4672", "Picture signal improvement (PSI) circuit", (const byte *)"\x44" }, 169 | { "TDA4680", "Video processor", (const byte *)"\x44" }, 170 | { "TDA4687", "Video processor", (const byte *)"\x44" }, 171 | { "TDA4688", "Video processor", (const byte *)"\x44" }, 172 | { "TDA4780", "Video control with gamma control", (const byte *)"\x44" }, 173 | { "TDA7433", "Basic function audio processor", (const byte *)"\x45" }, 174 | { "TDA8370", "High/medium perf. sync. processor", (const byte *)"\x46" }, 175 | { "TDA8376", "One-chip multistandard video", (const byte *)"\x45" }, 176 | { "TDA8415", "TVNCR stereo/dual sound processor", (const byte *)"\x42" }, 177 | { "TDA8417", "TVNCR stereo/dual sound processor", (const byte *)"\x42" }, 178 | { "TDA8421", "Audio processor with loudspeaker and headphone channel ", (const byte *)"\x41\x40" }, 179 | { "TDA8424", "Audio processor with loudspeaker channel", (const byte *)"\x41" }, 180 | { "TDA8425", "Audio processor with loudspeaker channel", (const byte *)"\x41" }, 181 | { "TDA8426", "Hi-fi stereo audio processor", (const byte *)"\x41" }, 182 | { "TDA8442", "Interface for colour decoder", (const byte *)"\x44" }, 183 | { "TDA9150", "Deflection processor", (const byte *)"\x46" }, 184 | { "TDA9860", "Hi-fi audio processor", (const byte *)"\x41\x40" }, 185 | { "TEA5767", "Radio receiver", (const byte *)"\x60" }, 186 | { "TEA6100", "FM/IF for computer-controlled radio", (const byte *)"\x61" }, 187 | { "TEA6300", "Sound fader control and preamplifier/source selector", (const byte *)"\x40" }, 188 | { "TEA6320", "4-input tone/volume controller with fader control", (const byte *)"\x40" }, 189 | { "TEA6330", "Sound fader control circuit for car radios", (const byte *)"\x40" }, 190 | { "TMP006", "Infrared Thermopile Sensor in Chip-Scale Package", (const byte *)"\x43\x41\x46\x47\x42\x40\x45\x44" }, 191 | { "TMP007", "IR Temperature sensor", (const byte *)"\x43\x41\x46\x47\x42\x40\x45\x44" }, 192 | { "TMP102", "Temperature sensor", (const byte *)"\x4b\x4a\x49\x48" }, 193 | { "TPA2016", "2.8-W/Ch Stereo Class-D Audio Amplifier With Dynamic Range Compression and Automatic Gain Control", (const byte *)"\x58" }, 194 | { "TSA5511", "1.3 GHz PLL frequency synthesizer for TV", (const byte *)"\x63\x61\x62\x60" }, 195 | { "TSL2561", "light sensor", (const byte *)"\x39\x49" }, 196 | { "TSL2591", "light sensor", (const byte *)"\x29" }, 197 | { "UMA1014T", "Low-power frequency synthesizer for mobile radio communications", (const byte *)"\x63\x62" }, 198 | { "VCNL40x0", "proximity sensor", (const byte *)"\x13" }, 199 | { "VCNL4200", "High Sensitivity Long Distance Proximity and Ambient Light Sensor With I2C Interface", (const byte *)"\x51" }, 200 | { "VEML6070", "UVA Light Sensor with I2C Interface", (const byte *)"\x39\x38" }, 201 | { "VEML6075", "UVA and UVB Light Sensor", (const byte *)"\x10" }, 202 | { "VEML7700", "High Accuracy Ambient Light Sensor ", (const byte *)"\x10" }, 203 | { "VL53L0x", "Time Of Flight distance sensor", (const byte *)"\x29" }, 204 | { "VL6180X", "Time Of Flight distance sensor", (const byte *)"\x29" }, 205 | { "VML6075", "UVA and UVB Light Sensor with I2C Interface", (const byte *)"\x10" }, 206 | }; 207 | 208 | int i2c_scanner_known_devices_length = sizeof(i2c_scanner_known_devices)/sizeof(i2c_device_t); 209 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "one_wire.h" 4 | 5 | #define MAX_WIFI_SSID_LENGTH 64 6 | #define MAX_WIFI_PASSWORD_LENGTH 64 7 | 8 | static char wifi_ssid[MAX_WIFI_SSID_LENGTH+1] = ""; 9 | static char wifi_password[MAX_WIFI_PASSWORD_LENGTH+1] = ""; 10 | 11 | static uint8_t one_wire_pin = 0xff; 12 | 13 | #ifdef ADC_MODE 14 | ADC_MODE(ADC_VCC); 15 | #endif 16 | 17 | void i2c_begin(), i2c_scan(), blink_start(int), wifi_begin(), wifi_scan(), wifi_info(), esp_output(), wifi_disconnect(), wifi_connect(const char*, const char*); 18 | 19 | bool wifi_connected(); 20 | 21 | void output_menu() { 22 | Serial.println("1. Show ESP information"); 23 | 24 | Serial.println("2. Enter wifi credentials"); 25 | 26 | if(wifi_connected()) 27 | Serial.printf("3. Disconnect from wifi network %s\n", wifi_ssid); 28 | else 29 | Serial.printf("3. Connect to wifi network %s\n", strlen(wifi_ssid) > 0 ? wifi_ssid : "(enter SSID to be able to connect)"); 30 | 31 | Serial.println("4. Current wifi info"); 32 | Serial.println("5. Scan wifi networks"); 33 | Serial.println("6. Scan I2C devices"); 34 | #if 0 35 | Serial.println("7. Scan BLE devices"); 36 | #endif 37 | // Serial.println("8. Scan 1 Wire devices"); 38 | Serial.println("0. Restart"); 39 | } 40 | 41 | 42 | void setup(){ 43 | Serial.begin(115200); 44 | 45 | // Serial.setDebugOutput(true); 46 | Serial.println(); 47 | Serial.println(); 48 | Serial.println("Hello World"); 49 | delay(5000); 50 | 51 | 52 | wifi_begin(); 53 | i2c_begin(); 54 | 55 | output_menu(); 56 | } 57 | 58 | void input_wifi_credentials(); 59 | void input_one_wire_pin(); 60 | 61 | void loop() { 62 | if (Serial.available() > 0) { 63 | char cmd[2]; 64 | 65 | Serial.readBytes(cmd, 1); 66 | 67 | switch(cmd[0]) { 68 | case '1': 69 | esp_output(); 70 | break; 71 | 72 | case '2': 73 | input_wifi_credentials(); 74 | break; 75 | 76 | case '3': 77 | if(wifi_connected()) 78 | wifi_disconnect(); 79 | else { 80 | if(strlen(wifi_ssid) > 0) 81 | wifi_connect(wifi_ssid, wifi_password); 82 | else 83 | Serial.println("You must enter a Wifi SSID first"); 84 | } 85 | 86 | break; 87 | 88 | case '4': 89 | if(strlen(wifi_ssid) > 0) { 90 | Serial.printf("Entered SSID: %s\n", wifi_ssid); 91 | Serial.printf("Entered password: %s\n", wifi_password); 92 | } else { 93 | Serial.println("No SSID entered"); 94 | } 95 | 96 | Serial.println(); 97 | 98 | wifi_info(); 99 | 100 | Serial.println(); 101 | Serial.println(); 102 | break; 103 | 104 | case '5': 105 | wifi_scan(); 106 | break; 107 | 108 | case '6': 109 | i2c_scan(); 110 | break; 111 | 112 | #if 0 113 | case '7': 114 | void SampleScan(); 115 | SampleScan(); 116 | break; 117 | #endif 118 | 119 | /* 120 | case '8': 121 | input_one_wire_pin(); 122 | one_wire_scan(one_wire_pin); 123 | break; 124 | */ 125 | 126 | case '0': 127 | Serial.println("RESTART ESP"); 128 | ESP.restart(); 129 | break; 130 | 131 | case 'h': 132 | case '?': 133 | case '\n': 134 | output_menu(); 135 | break; 136 | 137 | default: 138 | Serial.printf("Unknown command '%c'\n", cmd[0]); 139 | } 140 | } 141 | } 142 | 143 | /* basic line reading function which handles backspace and delete 144 | * can't believe I had to write this; I must be missing something... 145 | */ 146 | int serial_read_line(char* buf, int length) { 147 | int n = 0; 148 | 149 | while(1) { 150 | if(Serial.available() == 0) { 151 | yield(); 152 | continue; 153 | } 154 | 155 | char c = Serial.read(); 156 | 157 | // Serial.printf("%d", (int)c); 158 | 159 | if(c == -1 || c == '\n') { 160 | yield(); 161 | continue; 162 | } 163 | 164 | if(c == '\b' || c == 0x7f) { 165 | n--; 166 | buf[n] = '\0'; 167 | Serial.print('\b'); 168 | continue; 169 | } 170 | 171 | if(n == length) { 172 | Serial.print("\07"); 173 | continue; 174 | } 175 | 176 | if(c == '\r') { 177 | Serial.println(); 178 | return n; 179 | } 180 | 181 | Serial.print(c); 182 | 183 | buf[n++] = c; 184 | buf[n] = '\0'; 185 | } 186 | } 187 | 188 | 189 | void input_wifi_credentials() { 190 | Serial.println("Enter wifi SSID"); 191 | 192 | serial_read_line(wifi_ssid, MAX_WIFI_SSID_LENGTH); 193 | 194 | Serial.println("Enter wifi password"); 195 | 196 | serial_read_line(wifi_password, MAX_WIFI_PASSWORD_LENGTH); 197 | 198 | Serial.println(); 199 | Serial.println(); 200 | 201 | Serial.printf("SSID %s\n", wifi_ssid); 202 | Serial.printf("Password %s\n", wifi_password); 203 | 204 | Serial.println(); 205 | Serial.println(); 206 | } 207 | 208 | void input_one_wire_pin() { 209 | char pin_number[5]; 210 | 211 | Serial.println("Enter pin number for OneWire data"); 212 | 213 | serial_read_line(pin_number, 4); 214 | 215 | Serial.println(); 216 | Serial.println(); 217 | 218 | one_wire_pin = atoi(pin_number); 219 | Serial.printf("OneWire pin number %d\n", one_wire_pin); 220 | Serial.println("Remember to connect a 4.7K resistor between VCC and OneWire data!\n"); 221 | 222 | Serial.println(); 223 | Serial.println(); 224 | } 225 | 226 | -------------------------------------------------------------------------------- /src/one_wire.cpp: -------------------------------------------------------------------------------- 1 | #if 0 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "one_wire.h" 8 | 9 | 10 | void one_wire_scan(uint8_t pin) { 11 | OneWire oneWire(pin); 12 | byte i; 13 | byte addr[8]; 14 | 15 | for(int scan_count = 0; scan_count < 10; scan_count++) { 16 | if(!oneWire.search(addr)) { 17 | Serial.println(" No more addresses."); 18 | Serial.println(); 19 | oneWire.reset_search(); 20 | delay(250); 21 | continue; 22 | } 23 | Serial.print(" ROM ="); 24 | for(i = 0; i < 8; i++) { 25 | Serial.write(' '); 26 | Serial.print(addr[i], HEX); 27 | } 28 | } 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/one_wire.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | void one_wire_scan(uint8_t pin); 6 | -------------------------------------------------------------------------------- /src/wifi_connect.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ESP32 4 | #include 5 | #endif 6 | 7 | #ifdef ESP8266 8 | #include 9 | #endif 10 | 11 | #ifndef ESP32 12 | 13 | const char* connectionStatus(int); 14 | 15 | void eventWiFi(WiFiEvent_t event) { 16 | switch(event) { 17 | case WIFI_EVENT_STAMODE_CONNECTED: 18 | Serial.printf("[wifi] %d, Connected\n", event); 19 | break; 20 | 21 | case WIFI_EVENT_STAMODE_DISCONNECTED: 22 | Serial.printf("[wifi] %d, Disconnected - Status %d, %s\n", event, WiFi.status(), connectionStatus(WiFi.status())); 23 | break; 24 | 25 | case WIFI_EVENT_STAMODE_AUTHMODE_CHANGE: 26 | Serial.printf("[wifi] %d, AuthMode Change\n", event); 27 | break; 28 | 29 | case WIFI_EVENT_STAMODE_GOT_IP: 30 | Serial.printf("[wifi] %d, Got IP\n", event); 31 | break; 32 | 33 | case WIFI_EVENT_STAMODE_DHCP_TIMEOUT: 34 | Serial.printf("[wifi] %d, DHCP Timeout\n", event); 35 | break; 36 | 37 | case WIFI_EVENT_SOFTAPMODE_STACONNECTED: 38 | Serial.printf("[ap] %d, Client Connected\n", event); 39 | break; 40 | 41 | case WIFI_EVENT_SOFTAPMODE_STADISCONNECTED: 42 | Serial.printf("[ap] %d, Client Disconnected\n", event); 43 | break; 44 | 45 | case WIFI_EVENT_SOFTAPMODE_PROBEREQRECVED: 46 | Serial.printf("[ap] %d, Probe Request Recieved\n", event); 47 | break; 48 | 49 | default: 50 | Serial.printf("[GENERIC EVENT] %d\n", event); 51 | } 52 | } 53 | 54 | const char* connectionStatus(int status) { 55 | switch(status) { 56 | case WL_CONNECTED: 57 | return "Connected"; 58 | 59 | case WL_NO_SSID_AVAIL: 60 | return "Network not availible"; 61 | 62 | case WL_CONNECT_FAILED: 63 | return "Wrong password"; 64 | 65 | case WL_IDLE_STATUS: 66 | return "Idle status"; 67 | 68 | case WL_DISCONNECTED: 69 | return "Disconnected"; 70 | 71 | default: 72 | return "Unknown"; 73 | } 74 | } 75 | #endif 76 | 77 | void wifi_begin() { 78 | WiFi.setAutoConnect ( false ); // Autoconnect to last known Wifi on startup 79 | WiFi.setAutoReconnect ( false ); 80 | 81 | #ifndef ESP32 82 | WiFi.onEvent(eventWiFi); // Handle WiFi event 83 | #endif 84 | 85 | WiFi.mode(WIFI_STA); // Station mode 86 | } 87 | 88 | void wifi_connect(const char* ssid, const char* password) { 89 | WiFi.begin(ssid, password); 90 | 91 | Serial.println(); 92 | Serial.println(); 93 | Serial.print("Connecting"); 94 | while (WiFi.status() != WL_CONNECTED) { 95 | Serial.print("."); 96 | delay(200); 97 | } 98 | 99 | while (WiFi.waitForConnectResult() != WL_CONNECTED) { 100 | Serial.println(); 101 | Serial.println("Fail connecting"); 102 | } 103 | 104 | Serial.println(""); 105 | Serial.println("WiFi connected"); 106 | } 107 | 108 | void wifi_disconnect() { 109 | WiFi.disconnect(); 110 | } 111 | 112 | bool wifi_connected() { 113 | return WiFi.status() == WL_CONNECTED; 114 | } 115 | 116 | void wifi_info() { 117 | if(WiFi.status() == WL_CONNECTED) 118 | Serial.println("Connected"); 119 | else 120 | Serial.println("Not connected"); 121 | 122 | #ifndef ESP32 123 | Serial.println(String("Hostname ") + WiFi.hostname()); 124 | #endif 125 | Serial.println(String("MAC address ") + WiFi.macAddress()); 126 | 127 | if(WiFi.status() == WL_CONNECTED) { 128 | Serial.println(String("IP address ") + WiFi.localIP().toString()); 129 | Serial.println(String("Subnet mask ") + WiFi.subnetMask().toString()); 130 | Serial.println(String("router IP ") + WiFi.gatewayIP().toString()); 131 | Serial.println(String("first DNS server ") + WiFi.dnsIP(0).toString()); 132 | Serial.println(String("SSID ") + WiFi.SSID()); 133 | Serial.println(String("RSSi ") + WiFi.RSSI()); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/wifi_scanner.cpp: -------------------------------------------------------------------------------- 1 | #ifdef ESP32 2 | #include 3 | #endif 4 | 5 | #ifdef ESP8266 6 | #include 7 | #endif 8 | 9 | static const char* wifi_enc_type(int code) { 10 | #ifdef ESP32 11 | static char buf[6]; 12 | snprintf(buf, 6, "%d", code); 13 | return buf; 14 | #else 15 | 16 | switch(code) { 17 | case ENC_TYPE_WEP: 18 | return "WEP"; 19 | case ENC_TYPE_TKIP: 20 | return "TKIP"; 21 | case ENC_TYPE_CCMP: 22 | return "CCMP"; 23 | case ENC_TYPE_NONE: 24 | return "none"; 25 | case ENC_TYPE_AUTO: 26 | return "WPA/WPA2/PSK"; 27 | default: 28 | return "unknown"; 29 | } 30 | #endif 31 | } 32 | 33 | 34 | void wifi_scan() { 35 | WiFi.disconnect(); 36 | 37 | Serial.println("About to scan wifi networks"); 38 | 39 | int n = WiFi.scanNetworks(); 40 | 41 | Serial.println(); 42 | Serial.println("Wifi scan done"); 43 | if(n == 0) { 44 | Serial.println("no networks found"); 45 | } else { 46 | Serial.printf("%d networks found\n", n); 47 | Serial.printf("%32s %3s %3s %18s %s\n", "SSID", "CHN", "RSS", "MAC address", "Encryption"); 48 | for (int i = 0; i < n; ++i) { 49 | Serial.printf("%32s %3d %3d %18s %s\n", 50 | WiFi.SSID(i).c_str(), 51 | WiFi.channel(i), 52 | WiFi.RSSI(i), 53 | WiFi.BSSIDstr(i).c_str(), 54 | wifi_enc_type(WiFi.encryptionType(i))); 55 | } 56 | 57 | Serial.println(); 58 | } 59 | } 60 | 61 | --------------------------------------------------------------------------------