Skip to content

Commit

Permalink
Added static ipaddress example
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Feb 17, 2023
1 parent 3170435 commit 59e0989
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
79 changes: 79 additions & 0 deletions examples/BasicUnit/StaticIPAddress/StaticIPAddress.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @file StaticIPAddress.ino
* @author Lewis He ([email protected])
* @license MIT
* @copyright Copyright (c) 2023 Shenzhen Xin Yuan Electronic Technology Co., Ltd
* @date 2023-02-17
*
*/

#include "config.h"
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <SPIFFS.h>
#include <FS.h>
#include <HTTPClient.h>

TTGOClass *ttgo = nullptr;

const char *ssid = "yourNetworkName";
const char *password = "yourNetworkPass";

//IPAddress
IPAddress staticIP(192, 168, 0, 113);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(192, 168, 0, 1);

void setup()
{
Serial.begin(115200);

// Get Watch Instance
ttgo = TTGOClass::getWatch();

// Initialize watch
ttgo->begin();

// Register lvgl
ttgo->lvgl_begin();

// Turn on the backlight
ttgo->openBL();

// Register wifi events
WiFi.mode(WIFI_STA);

WiFi.begin(ssid, password);

if (WiFi.config(staticIP, gateway, subnet, dns, dns) == false) {
Serial.println("Configuration failed.");
}

while (WiFi.status() != WL_CONNECTED) {
Serial.print("."); delay(50);
}

Serial.println();
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

Serial.print("Local IP: ");
Serial.println(WiFi.localIP());
Serial.print("Subnet Mask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway IP: ");
Serial.println(WiFi.gatewayIP());
Serial.print("DNS 1: ");
Serial.println(WiFi.dnsIP(0));
Serial.print("DNS 2: ");
Serial.println(WiFi.dnsIP(1));

}


void loop()
{

}
29 changes: 29 additions & 0 deletions examples/BasicUnit/StaticIPAddress/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// => Hardware select
// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
#define LILYGO_WATCH_2020_V1 // To use T-Watch2020 V1, please uncomment this line
// #define LILYGO_WATCH_2020_V2 // To use T-Watch2020 V2, please uncomment this line
// #define LILYGO_WATCH_2020_V3 // To use T-Watch2020 V3, please uncomment this line

// #define LILYGO_LILYPI_V1 //LILYPI / TBLOCK requires an external display module
// #define LILYGO_WATCH_BLOCK //LILYPI / TBLOCK requires an external display module



#if defined(LILYGO_LILYPI_V1) || defined(LILYGO_WATCH_BLOCK)
// #define LILYGO_BLOCK_ST7796S_MODULE //Use ST7796S
// #define LILYGO_BLOCK_ILI9481_MODULE //Use ILI9841
// #define LILYGO_GC9A01A_MODULE //Use GC9A01A
#endif
#define LILYGO_WATCH_LVGL //To use LVGL, you need to enable the macro LVGL
#define LILYGO_WATCH_LVGL_FS
#define LILYGO_WATCH_LVGL_DECODER //Need to use PNG decoding, to define this macro


#if defined(LILYGO_WATCH_2019_WITH_TOUCH)
#define LILYGO_WATCH_LVGL_FS_SPIFFS
#endif
// #define LILYGO_WATCH_HAS_SDCARD

#include <LilyGoWatch.h>

0 comments on commit 59e0989

Please sign in to comment.