Add public ip to wifi page
This commit is contained in:
parent
b2cde0d8ce
commit
fa32bcfad8
@ -97,7 +97,7 @@ void wifi::update_texture(){
|
|||||||
|
|
||||||
//show info about the network
|
//show info about the network
|
||||||
tgt.x = (SCREEN_WIDTH / 2) + 25;
|
tgt.x = (SCREEN_WIDTH / 2) + 25;
|
||||||
tgt.y = 50;
|
tgt.y = 60;
|
||||||
TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }),
|
TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }),
|
||||||
network_string.c_str(), &tgt.w, &tgt.h);
|
network_string.c_str(), &tgt.w, &tgt.h);
|
||||||
SDL_RenderCopy(board::getRenderer(),
|
SDL_RenderCopy(board::getRenderer(),
|
||||||
@ -113,6 +113,31 @@ void wifi::update_texture(){
|
|||||||
board::getString(password_string.c_str(),
|
board::getString(password_string.c_str(),
|
||||||
{ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt);
|
{ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt);
|
||||||
|
|
||||||
|
//Get public ip address and display it
|
||||||
|
if(WIFI_SHOW_PUBLIC_IP){
|
||||||
|
std::string public_ip = "WAN IP: ";
|
||||||
|
CURL* curl;
|
||||||
|
curl = curl_easy_init();
|
||||||
|
|
||||||
|
if(curl){
|
||||||
|
CURLcode res;
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, WIFI_PUBLIC_IP_URL);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
|
||||||
|
dashboard::panel::curl_callback);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &public_ip);
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
} else {
|
||||||
|
public_ip += "Unkown";
|
||||||
|
}
|
||||||
|
|
||||||
|
tgt.y += tgt.h + 25;
|
||||||
|
TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }),
|
||||||
|
public_ip.c_str(), &tgt.w, &tgt.h);
|
||||||
|
SDL_RenderCopy(board::getRenderer(),
|
||||||
|
board::getString(public_ip.c_str(),
|
||||||
|
{ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SDL_SetRenderTarget(board::getRenderer(), NULL);
|
SDL_SetRenderTarget(board::getRenderer(), NULL);
|
||||||
@ -133,3 +158,9 @@ void wifi::initTexture(){
|
|||||||
SDL_SetTextureBlendMode(_texture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(_texture, SDL_BLENDMODE_BLEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t dashboard::panel::curl_callback(void* contents, size_t size,
|
||||||
|
size_t nmemb, void* userp){
|
||||||
|
((std::string*)userp)->append((char*)contents, size * nmemb);
|
||||||
|
return size * nmemb;
|
||||||
|
}
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include <SDL2/SDL_ttf.h>
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace dashboard::panel {
|
namespace dashboard::panel {
|
||||||
@ -26,6 +28,8 @@ namespace dashboard::panel {
|
|||||||
void update_texture();
|
void update_texture();
|
||||||
void initTexture();
|
void initTexture();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
size_t curl_callback(void*, size_t, size_t, void*);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "../board.hpp"
|
#include "../board.hpp"
|
||||||
|
@ -15,9 +15,16 @@ namespace dashboard::panel {
|
|||||||
//Due to the nature of this panel, this value is ignored
|
//Due to the nature of this panel, this value is ignored
|
||||||
constexpr size_t WIFI_UPDATE_INTERVAL = 60000;
|
constexpr size_t WIFI_UPDATE_INTERVAL = 60000;
|
||||||
|
|
||||||
|
//Set to true to have your public IP be shown on the wifi page
|
||||||
|
//Will make a curl request to WIFI_PUBLIC_IP_URL when the frame
|
||||||
|
//is rendered. This this is a privacy concern disable this option
|
||||||
|
constexpr bool WIFI_SHOW_PUBLIC_IP = true;
|
||||||
|
constexpr char WIFI_PUBLIC_IP_URL[] = "http://ipinfo.io/ip";
|
||||||
|
|
||||||
//All of the following options WILL be shown on the screen.
|
//All of the following options WILL be shown on the screen.
|
||||||
//If this is a privacy concernt for you, set the value to be blank
|
//If this is a privacy concernt for you, set the value to be blank
|
||||||
//(ie "") and it will not be shown
|
//(ie "") and it will not be shown
|
||||||
constexpr char WIFI_NETWORK_NAME[] = "MyNetwork";
|
constexpr char WIFI_NETWORK_NAME[] = "MyNetwork";
|
||||||
constexpr char WIFI_NETWORK_PASS[] = "MyPassword";
|
constexpr char WIFI_NETWORK_PASS[] = "MyPassword";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user