mirror of
https://gitee.com/peng_zhihui/HoloCubic
synced 2025-11-04 21:19:40 +08:00
[Fw] Add Bilibili get fans count fuction.
This commit is contained in:
parent
8c3673431e
commit
e97da51439
@ -1,10 +1,9 @@
|
|||||||
#include <WiFi.h>
|
|
||||||
#include <HTTPClient.h>
|
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "imu.h"
|
#include "imu.h"
|
||||||
#include "rgb_led.h"
|
|
||||||
#include "ambient.h"
|
#include "ambient.h"
|
||||||
|
#include "network.h"
|
||||||
#include "sd_card.h"
|
#include "sd_card.h"
|
||||||
|
#include "rgb_led.h"
|
||||||
#include "lv_port_indev.h"
|
#include "lv_port_indev.h"
|
||||||
#include "lv_cubic_gui.h"
|
#include "lv_cubic_gui.h"
|
||||||
|
|
||||||
@ -17,6 +16,7 @@ IMU mpu;
|
|||||||
Pixel rgb;
|
Pixel rgb;
|
||||||
Ambient ambLight;
|
Ambient ambLight;
|
||||||
SdCard tf;
|
SdCard tf;
|
||||||
|
Network wifi;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@ -26,76 +26,33 @@ void setup()
|
|||||||
screen.init();
|
screen.init();
|
||||||
screen.setBackLight(0.2);
|
screen.setBackLight(0.2);
|
||||||
|
|
||||||
|
|
||||||
/*** Init IMU as input device ***/
|
/*** Init IMU as input device ***/
|
||||||
lv_port_indev_init();
|
lv_port_indev_init();
|
||||||
mpu.init();
|
mpu.init();
|
||||||
|
|
||||||
|
|
||||||
/*** Init on-board RGB ***/
|
/*** Init on-board RGB ***/
|
||||||
rgb.init();
|
rgb.init();
|
||||||
rgb.setBrightness(0.1).setRGB(0, 122, 204);
|
rgb.setBrightness(0.1).setRGB(0, 122, 204);
|
||||||
|
|
||||||
|
|
||||||
/*** Init ambient-light sensor ***/
|
/*** Init ambient-light sensor ***/
|
||||||
ambLight.init(ONE_TIME_L_RESOLUTION_MODE);
|
ambLight.init(ONE_TIME_L_RESOLUTION_MODE);
|
||||||
|
|
||||||
|
|
||||||
/*** Init micro SD-Card ***/
|
/*** Init micro SD-Card ***/
|
||||||
tf.init();
|
tf.init();
|
||||||
|
String ssid = tf.readFileLine("/wifi.txt", 1); // line-1 for WiFi ssid
|
||||||
|
String password = tf.readFileLine("/wifi.txt", 2); // line-2 for WiFi password
|
||||||
|
|
||||||
/*** Read WiFi info in SD-Card, then scan & connect WiFi ***/
|
/*** Read WiFi info in SD-Card, then scan & connect WiFi ***/
|
||||||
String ssid = tf.readFileLine("/wifi.txt", 1);
|
wifi.init(ssid, password);
|
||||||
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 ***/
|
/*** Inflate GUI objects ***/
|
||||||
//lv_demo_benchmark();
|
//lv_demo_benchmark();
|
||||||
lv_demo_encoder();
|
//lv_demo_encoder();
|
||||||
|
lv_holo_cubic_gui();
|
||||||
|
|
||||||
|
|
||||||
|
Serial.println(wifi.getBilibiliFans("http://api.bilibili.com/x/relation/stat?vmid=20259914"));
|
||||||
|
|
||||||
|
|
||||||
/*tf.listDir("/", 0);
|
/*tf.listDir("/", 0);
|
||||||
tf.createDir("/mydir");
|
tf.createDir("/mydir");
|
||||||
@ -122,7 +79,7 @@ void loop()
|
|||||||
mpu.update(200);
|
mpu.update(200);
|
||||||
|
|
||||||
rgb.setBrightness(ambLight.getLux() / 500.0);
|
rgb.setBrightness(ambLight.getLux() / 500.0);
|
||||||
//Serial.println(ambLight.getLux());
|
Serial.println(ambLight.getLux());
|
||||||
|
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
|
|||||||
75
2.Firmware/HoloCubic_fw/network.cpp
Normal file
75
2.Firmware/HoloCubic_fw/network.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "network.h"
|
||||||
|
|
||||||
|
|
||||||
|
void Network::init(String ssid, String password)
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int Network::getBilibiliFans(String url)
|
||||||
|
{
|
||||||
|
String fansCount = "";
|
||||||
|
HTTPClient http;
|
||||||
|
http.begin(url);
|
||||||
|
|
||||||
|
// start connection and send HTTP headerFFF
|
||||||
|
int httpCode = http.GET();
|
||||||
|
|
||||||
|
// httpCode will be negative on error
|
||||||
|
if (httpCode > 0)
|
||||||
|
{
|
||||||
|
// file found at server
|
||||||
|
if (httpCode == HTTP_CODE_OK)
|
||||||
|
{
|
||||||
|
String payload = http.getString();
|
||||||
|
int pos = (payload.indexOf("follower"));
|
||||||
|
fansCount = payload.substring(pos + 10, payload.length() - 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
|
||||||
|
}
|
||||||
|
http.end();
|
||||||
|
|
||||||
|
return atol(fansCount.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
18
2.Firmware/HoloCubic_fw/network.h
Normal file
18
2.Firmware/HoloCubic_fw/network.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef NETWORK_H
|
||||||
|
#define NETWORK_H
|
||||||
|
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <HTTPClient.h>
|
||||||
|
|
||||||
|
|
||||||
|
class Network
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
public:
|
||||||
|
void init(String ssid, String password);
|
||||||
|
unsigned int getBilibiliFans(String url);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user