2026年1月7日 星期三

ESP32-CAM 實作 RTSP 多人連接

ESP32-CAM 實作 RTSP 多人連接主要受限於硬體資源(CPU 與記憶體)及軟體架構。一般預設範例僅支援單一連線,若需多人同時查看,請參考以下:
ESP32-RTSPServer:這是一個現代化的庫,支援多人同時連線(Multicast 或 Unicast),並可設定連線數上限(例如 maxRTSPClients = 5)。

在專案中的
void setup() {}中, 新增
rtspServer.maxRTSPClients = 5;
這樣就可以同時5個連線




針對固定USB裝置上帶出的Com port號碼進行清除

針對相同硬體不同SN的裝置, 在系統所帶出的COM Port號碼, 會越來越多. 
可透過pnputil.exe這個工具來進行清除.
以下是在c#的環境所編寫
// 例如"USB\VID_XXXX&PID_XXXX\XXXXXXXX"
public void RemoveDeviceByInstanceId(string instanceId)
{

//ProcessStartInfo psi = new ProcessStartInfo("pnputil.exe");

ProcessStartInfo psi = new ProcessStartInfo();

psi.FileName = @"C:\Windows\System32\pnputil.exe";

psi.Arguments = $"/remove-device /deviceid \"{instanceId}\""; 

psi.RedirectStandardOutput = true; // 重新導向標準輸出

psi.RedirectStandardError = true; // 重新導向錯誤輸出

psi.UseShellExecute = false; // 必須設為 false 才能重新導向輸出

psi.CreateNoWindow = true; // 不建立視窗

try

{

using (Process p = Process.Start(psi))

{

// 讀取輸出流

string output = p.StandardOutput.ReadToEnd();

string error = p.StandardError.ReadToEnd();

p.WaitForExit();

Console.WriteLine("PnPUtil 輸出: " + output);

ATECtl.GridData.WriteMessage(ATECtl.GridData._TPars.richtextbox, "PnPUtil 輸出:", output, Color.Blue, Color.Green);

Console.WriteLine("PnPUtil 錯誤: " + error);

ATECtl.GridData.WriteMessage(ATECtl.GridData._TPars.richtextbox, "PnPUtil 錯誤", error, Color.Blue, Color.Green);

Console.WriteLine($"結束代碼: {p.ExitCode}");

ATECtl.GridData.WriteMessage(ATECtl.GridData._TPars.richtextbox, "結束代碼", $"{p.ExitCode}", Color.Blue, Color.Green);

}

}

catch (Exception ex)

{

Console.WriteLine($"執行 Process.Start 失敗 (檔案可能不存在): {ex.Message}");

ATECtl.GridData.WriteMessage(ATECtl.GridData._TPars.richtextbox, "執行 Process.Start 失敗 (檔案可能不存在)", "", Color.Blue, Color.Green);

}

}