This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PublicDependencyModuleNames.AddRange( | |
new string[] | |
{ | |
"HTTP", | |
"HTTPServer", | |
"Networking", | |
"Sockets", | |
"VaRest", // 我的專案是使用這個處理 Json | |
} | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "CoreMinimal.h" | |
#include "Sybsystems/GameInstanceSybsystem.h" | |
#include "HttpLauncher.generated.h" | |
UCLASS() | |
class API_NAME UHttpLauncher : public UGameInstanceSubsystem | |
{ | |
GENERATED_BODY() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HttpLauncher.h" | |
TWeakObjectPtr<UHttpLauncher> UHttpLauncher::_instance == nullptr; | |
UHttpLauncher* UHttpLauncher::Instance() { return _instance.Get(); } | |
void UHttpLauncher::Initialize(FSubsystemCollectionBase& Collection) | |
{ | |
_instance = this; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "CoreMinimal.h" | |
#include "HttpServerRequest.h" | |
#include "HttpResultCallback.h" | |
#include "UHttpListener.generated.h" | |
UCLASS() | |
class API_NAME UHttpListener : public UObject | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HttpPath.h" | |
#include "IHttpRouter.h" | |
#include "HttpServerHttpVersion.h" | |
#include "HttpServerModule.h" | |
#include "HttpServerResponse.h" | |
#include "Sockets.h" | |
#include "SocketSubsystem.h" | |
UHttpListener::UHttpListener() | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WiFi Info | |
const char* WIFI_SSID = "YOUR_WIFI_SSID"; | |
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD"; | |
// Device Info | |
const char* DEVICE_NAME = "YOUR_CUSTOM_DEVICE_ID_OR_NAME"; | |
const int DEVICE_WIFI_CONNECT_TIME_OUT = 15; | |
// Firebase Info | |
const char FIREBASE_PRIVATE_KEY[] PROGMEM = "YOUR_PROJECT_PRIVATE_KEY"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <WiFi.h> | |
void connectToWiFi() { | |
// 設定 WiFi 模式 | |
WiFi.mode(WIFI_STA); | |
// 設定名稱 | |
WiFi.setHostname(DEVICE_NAME); | |
// Connect | |
WiFi.begin(WIFI_SSID, WIFI_PASS); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Firebase_ESP_Client.h> | |
#include <addons/TokenHelper.h> | |
// Firebase Variable | |
FirebaseData data; | |
FirebaseConfig config; | |
FirebaseAuth auth; | |
void connectToServer() { | |
auth.user.email = "User email"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void uploadData() { | |
// 設定 HTTP POST 參數 | |
FirebaseJson payload; | |
payload.set("deviceId", DEVICE_NAME); | |
// 直接從腳位抓直帶入 | |
payload.set("moisture", analogRead(A0); | |
if (Firebase.functions.callFunction(&data, | |
FIREBASE_ID, | |
FIREBASE_PROJECT_LOCATION, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool taskCompleted = false; | |
void setup() { | |
Serial.begin(115200); | |
connectToWiFi(); | |
connectToServer(); | |
} | |
void loop() { | |
if (Firebase.ready() && !taskCompleted) { |
OlderNewer