|
| 1 | +/** |
| 2 | + * @file StaticIPAddress.ino |
| 3 | + * @author Lewis He ([email protected]) |
| 4 | + * @license MIT |
| 5 | + * @copyright Copyright (c) 2023 Shenzhen Xin Yuan Electronic Technology Co., Ltd |
| 6 | + * @date 2023-02-17 |
| 7 | + * |
| 8 | + */ |
| 9 | + |
| 10 | +#include "config.h" |
| 11 | +#include <WiFi.h> |
| 12 | +#include <WiFiClientSecure.h> |
| 13 | +#include <SPIFFS.h> |
| 14 | +#include <FS.h> |
| 15 | +#include <HTTPClient.h> |
| 16 | + |
| 17 | +TTGOClass *ttgo = nullptr; |
| 18 | + |
| 19 | +const char *ssid = "yourNetworkName"; |
| 20 | +const char *password = "yourNetworkPass"; |
| 21 | + |
| 22 | +//IPAddress |
| 23 | +IPAddress staticIP(192, 168, 0, 113); |
| 24 | +IPAddress gateway(192, 168, 0, 1); |
| 25 | +IPAddress subnet(255, 255, 255, 0); |
| 26 | +IPAddress dns(192, 168, 0, 1); |
| 27 | + |
| 28 | +void setup() |
| 29 | +{ |
| 30 | + Serial.begin(115200); |
| 31 | + |
| 32 | + // Get Watch Instance |
| 33 | + ttgo = TTGOClass::getWatch(); |
| 34 | + |
| 35 | + // Initialize watch |
| 36 | + ttgo->begin(); |
| 37 | + |
| 38 | + // Register lvgl |
| 39 | + ttgo->lvgl_begin(); |
| 40 | + |
| 41 | + // Turn on the backlight |
| 42 | + ttgo->openBL(); |
| 43 | + |
| 44 | + // Register wifi events |
| 45 | + WiFi.mode(WIFI_STA); |
| 46 | + |
| 47 | + WiFi.begin(ssid, password); |
| 48 | + |
| 49 | + if (WiFi.config(staticIP, gateway, subnet, dns, dns) == false) { |
| 50 | + Serial.println("Configuration failed."); |
| 51 | + } |
| 52 | + |
| 53 | + while (WiFi.status() != WL_CONNECTED) { |
| 54 | + Serial.print("."); delay(50); |
| 55 | + } |
| 56 | + |
| 57 | + Serial.println(); |
| 58 | + Serial.println("WiFi connected"); |
| 59 | + Serial.println("IP address: "); |
| 60 | + Serial.println(WiFi.localIP()); |
| 61 | + |
| 62 | + Serial.print("Local IP: "); |
| 63 | + Serial.println(WiFi.localIP()); |
| 64 | + Serial.print("Subnet Mask: "); |
| 65 | + Serial.println(WiFi.subnetMask()); |
| 66 | + Serial.print("Gateway IP: "); |
| 67 | + Serial.println(WiFi.gatewayIP()); |
| 68 | + Serial.print("DNS 1: "); |
| 69 | + Serial.println(WiFi.dnsIP(0)); |
| 70 | + Serial.print("DNS 2: "); |
| 71 | + Serial.println(WiFi.dnsIP(1)); |
| 72 | + |
| 73 | +} |
| 74 | + |
| 75 | + |
| 76 | +void loop() |
| 77 | +{ |
| 78 | + |
| 79 | +} |
0 commit comments