mirror of
https://gitee.com/peng_zhihui/HoloCubic
synced 2025-09-27 02:19:11 +08:00
[Fw] Add WiFi connection functions.
This commit is contained in:
parent
38c030b3d4
commit
8c3673431e
@ -1,14 +1,17 @@
|
||||
#include <WiFi.h>
|
||||
#include <HTTPClient.h>
|
||||
#include "display.h"
|
||||
#include "imu.h"
|
||||
#include "rgb_led.h"
|
||||
#include "ambient.h"
|
||||
#include "sd_card.h"
|
||||
|
||||
#include "lv_port_indev.h"
|
||||
#include "lv_demo_encoder.h"
|
||||
#include "lv_cubic_gui.h"
|
||||
|
||||
#include "lv_demo_encoder.h"
|
||||
|
||||
|
||||
/*** Component objects ***/
|
||||
Display screen;
|
||||
IMU mpu;
|
||||
Pixel rgb;
|
||||
@ -19,26 +22,80 @@ void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
/*** Init screen ***/
|
||||
screen.init();
|
||||
screen.setBackLight(0.2);
|
||||
lv_port_indev_init();
|
||||
|
||||
|
||||
/*** Init IMU as input device ***/
|
||||
lv_port_indev_init();
|
||||
mpu.init();
|
||||
|
||||
|
||||
/*** Init on-board RGB ***/
|
||||
rgb.init();
|
||||
rgb.setBrightness(0.1).setRGB(0, 122, 204);
|
||||
|
||||
|
||||
/*** Init ambient-light sensor ***/
|
||||
ambLight.init(ONE_TIME_L_RESOLUTION_MODE);
|
||||
|
||||
|
||||
/*** Init micro SD-Card ***/
|
||||
tf.init();
|
||||
|
||||
|
||||
/*** Read WiFi info in SD-Card, then scan & connect WiFi ***/
|
||||
String ssid = tf.readFileLine("/wifi.txt", 1);
|
||||
String password = tf.readFileLine("/wifi.txt", 2);
|
||||
|
||||
Serial.println("scan start");
|
||||
|
||||
int n = WiFi.scanNetworks();
|
||||
Serial.println("scan done");
|
||||
if (n == 0)
|
||||
{
|
||||
Serial.println("no networks found");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(n);
|
||||
Serial.println(" networks found");
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
Serial.print(i + 1);
|
||||
Serial.print(": ");
|
||||
Serial.print(WiFi.SSID(i));
|
||||
Serial.print(" (");
|
||||
Serial.print(WiFi.RSSI(i));
|
||||
Serial.print(")");
|
||||
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.print("Connecting: ");
|
||||
Serial.print(ssid.c_str());
|
||||
Serial.print(" @");
|
||||
Serial.println(password.c_str());
|
||||
|
||||
WiFi.begin(ssid.c_str(), password.c_str());
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
|
||||
/*** Inflate GUI objects ***/
|
||||
//lv_demo_benchmark();
|
||||
lv_demo_encoder();
|
||||
|
||||
|
||||
Serial.print(tf.readFileLine("/wifi.txt", 1) + "\n");
|
||||
|
||||
Serial.print(tf.readFileLine("/wifi.txt", 2));
|
||||
|
||||
/*tf.listDir("/", 0);
|
||||
tf.createDir("/mydir");
|
||||
|
@ -128,7 +128,7 @@ void SdCard::readFile(const char* path)
|
||||
|
||||
String SdCard::readFileLine(const char* path, int num = 1)
|
||||
{
|
||||
Serial.printf("Reading file: %s\n", path);
|
||||
Serial.printf("Reading file: %s line: %d\n", path, num);
|
||||
|
||||
File file = SD.open(path);
|
||||
if (!file)
|
||||
@ -146,8 +146,9 @@ String SdCard::readFileLine(const char* path, int num = 1)
|
||||
if (num == 0)
|
||||
{
|
||||
*(p++) = '\0';
|
||||
|
||||
return String(buf);
|
||||
String s(buf);
|
||||
s.trim();
|
||||
return s;
|
||||
}
|
||||
}
|
||||
else if (num == 1)
|
||||
|
Loading…
Reference in New Issue
Block a user