ÆÄ¿ö¸µÅ©µî·Ï¾È³»
transmission¿¡¼ ´Ù¿î¹Þ´Â ¼Óµµ¸¦ º¸¿©ÁÝ´Ï´Ù.
esp8266: 1.75$(+¹è¼Û 1.15$)
tm1637: 0.75$(+¹è¼Û 0.99$)
¾ÆµÎÀ̳ë ÇÁ·Î±×·¡¹ÖÀº ¸øÇϴµ¥ ChatGPT¿¡
esp8266À» ÀÌ¿ëÇÏ¿© transmission ´Ù¿î·Îµå ¼Óµµ¸¦ ¹Þ¾Æ¿À´Â¹æ¹ýÀ» ¹°¾îº¸´Ï ÄÚµùÇØÁá½À´Ï´Ù.
½Ã°è¿ëÀ̶ó ÀÁ¡Àº ¸ÅÁ÷À¸·Î Áö¿ü½À´Ï´Ù.
-- ÀÌÇÏ ¾Æ·¡´Â »ç¿ëÇÑ ÄÚµå
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#include <Base64.h>
#include <TM1637Display.h>
// CLK ÇÉ°ú DIO ÇÉÀ» ¼³Á¤ÇÕ´Ï´Ù.
const int CLK_PIN = D2; // CLK ÇÉÀ» D2¿¡ ¿¬°á
const int DIO_PIN = D3; // DIO ÇÉÀ» D3¿¡ ¿¬°á
TM1637Display display(CLK_PIN, DIO_PIN);
const char* ssid = "°øÀ¯±âSSID";
const char* password = "°øÀ¯±â¾ÏÈ£";
const char* transmissionAddress = "Æ®·£½º¹Ì¼Ç ÁÖ¼Ò";
const int transmissionPort = 9091;
const char* rpcPath = "/transmission/rpc/";
const char* transmissionUsername = "Æ®·£½º¹Ì¼Ç ¾ÆÀ̵ð";
const char* transmissionPassword = "Æ®·£½º¹Ì¼Ç ¾ÏÈ£";
int times = 10;
String session_id;
double downloadSpeedArray[10]; // ÃÖ±Ù 10ÃÊ µ¿¾ÈÀÇ ´Ù¿î·Îµå ¼Óµµ¸¦ ÀúÀåÇÒ ¹è¿
unsigned long lastSpeedCheckTime = 0; // ¸¶Áö¸· ¼Óµµ È®ÀÎ ½Ã°£
int currentIndex = 0; // ´Ù¿î·Îµå ¼Óµµ ¹è¿ÀÇ ÇöÀç À妽º
void setup() {
Serial.begin(115200);
display.setBrightness(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.println("IP address: " + WiFi.localIP().toString());
// ¿¬°áµÈ Wi-Fi ³×Æ®¿öÅ©ÀÇ ·ÎÄà IP ÁÖ¼Ò¸¦ °¡Á®¿È
IPAddress localIP = WiFi.localIP();
// IP ÁÖ¼ÒÀÇ °¢ ¼¼±×¸ÕÆ®¸¦ 4ÀÚ¸®ÀÇ Á¤¼ö·Î º¯È¯
int ipSegments[4];
for (int i = 0; i < 4; i++) {
ipSegments[i] = localIP[i];
}
// º¯È¯µÈ °ªÀ» ½Ã¸®¾ó ¸ð´ÏÅÍ¿¡ Ãâ·Â
Serial.print("Local IP Address as 4-digit integers: ");
for (int i = 0; i < 4; i++) {
Serial.print(ipSegments[i]);
if (i < 3) {
Serial.print(", ");
}
}
display.clear();
display.showNumberDecEx(ipSegments[3], 0b00000000, false, 3, 1) ;
Serial.println();
delay(3000);
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = "http://" + String(transmissionAddress) + ":" + String(transmissionPort) + rpcPath;
String auth = base64::encode(String(transmissionUsername) + ":" + String(transmissionPassword));
WiFiClient client; // Create a WiFiClient object
http.begin(client, url); // Use the WiFiClient object in the begin function
http.addHeader("Content-Type", "application/json");
http.addHeader("Authorization", "Basic " + auth);
http.addHeader("X-Transmission-Session-Id", session_id);
// Send Transmission RPC request
int httpResponseCode = http.POST("{\"method\":\"session-stats\"}");
if (httpResponseCode == 409) {
String responseString = http.getString();
// X-Transmission-Session-Id °ªÀ» ÃßÃâÇÏ´Â ºÎºÐ
int idStart = responseString.indexOf("X-Transmission-Session-Id: ") + 27; // Çì´õÀÇ ½ÃÀÛ À§Ä¡
int idEnd = responseString.indexOf("</code>", idStart); // Çì´õÀÇ ³¡ À§Ä¡
session_id = responseString.substring(idStart, idEnd);
Serial.print("Session ID: ");
Serial.println(session_id);
} else if (httpResponseCode > 0) {
String response = http.getString();
// Parse JSON response
int uploadSpeed = response.substring(response.indexOf("\"uploadSpeed\"") + 14, response.indexOf(",", response.indexOf("\"uploadSpeed\""))).toInt();
int downloadSpeed = response.substring(response.indexOf("\"downloadSpeed\"") + 16, response.indexOf("}", response.indexOf("\"downloadSpeed\""))).toInt();
// Calculate moving average
unsigned long currentTime = millis();
double averageSpeed = 0;
if (currentTime - lastSpeedCheckTime >= 1000) {
lastSpeedCheckTime = currentTime;
downloadSpeedArray[currentIndex] = downloadSpeed;
currentIndex++;
if (currentIndex >= times) {
currentIndex = 0;
}
// Calculate average speed
averageSpeed = 0;
for (int i = 0; i < times; i++) {
averageSpeed += downloadSpeedArray[i];
}
averageSpeed /= times;
}
display.showNumberDecEx(averageSpeed/1000/10, 0x40, false, 4, 0) ; // turn on colon ¿øº»Àº 0x80 >> 3 Àε¥ ÄÝ·ÐÀÌ on µÇÁö ¾Ê¾Æ 0x80 >> 1 ·Î º¯°æ
} else {
Serial.print("Error during HTTP request. Status code: ");
Serial.println(httpResponseCode);
}
http.end();
}
delay(1000); // Adjust the delay based on your needs
}