@@ -315,12 +315,35 @@ const char *uploadPage PROGMEM = R"rawliteral(
315315 });
316316 }
317317
318+ function updateCanSpeed() {
319+ const select = document.getElementById('canSpeedSelect');
320+ const speed = select.value;
321+ fetch('/canspeed', {
322+ method: 'POST',
323+ headers: {'Content-Type': 'application/x-www-form-urlencoded'},
324+ body: 'speed=' + speed
325+ })
326+ .then(response => response.text())
327+ .then(data => {
328+ alert('CAN speed updated: ' + speed + ' bps');
329+ });
330+ }
331+ function loadCanSpeed() {
332+ fetch('/canspeed')
333+ .then(response => response.text())
334+ .then(speed => {
335+ const select = document.getElementById('canSpeedSelect');
336+ if (select) select.value = speed;
337+ });
338+ }
339+
318340 const startTime = Date.now()/1000;
319341 setInterval(refreshStatus, 1000);
320342
321343 // Load display config on page load
322344 window.onload = function() {
323345 loadDisplayConfig();
346+ loadCanSpeed();
324347 };
325348 </script>
326349 </head>
@@ -595,6 +618,21 @@ const char *uploadPage PROGMEM = R"rawliteral(
595618 WiFi will automatically turn off after 1 minute of inactivity to save power.
596619 </p>
597620 </div>
621+
622+ <div class="section">
623+ <h2>CAN Bus Configuration</h2>
624+ <div class="config-item">
625+ <label for="canSpeedSelect">CAN Speed:</label>
626+ <select id="canSpeedSelect" onchange="updateCanSpeed()">
627+ <option value="500000">500 Kbps</option>
628+ <option value="1000000">1 Mbps</option>
629+ </select>
630+ </div>
631+ <p style="font-size: 14px; opacity: 0.8;">
632+ Pilih kecepatan CAN sesuai kebutuhan hardware/ECU Anda.<br>
633+ Perubahan akan disimpan dan digunakan saat restart berikutnya.
634+ </p>
635+ </div>
598636 </div>
599637 </body>
600638</html>
@@ -678,7 +716,7 @@ void startWebServer()
678716 server.on (" /status" , HTTP_GET , [&]()
679717 {
680718 String json = " {" ;
681- json += " \" commMode\" :\" " + String (isCANMode ? " CAN Bus" : " Serial" ) + " \" ," ;
719+ json += " \" commMode\" :\" " + String (commMode == COMM_CAN ? " CAN Bus" : " Serial" ) + " \" ," ;
682720 json += " \" debugMode\" :" + String (debugMode ? " true" : " false" ) + " ," ;
683721#if ENABLE_SIMULATOR
684722 json += " \" simulatorMode\" :" + String (getSimulatorMode ()) + " ," ;
@@ -790,10 +828,14 @@ void startWebServer()
790828 server.send (200 , " application/json" , json);
791829 });
792830
831+ server.on (" /canspeed" , HTTP_GET , handleCanSpeed);
832+ server.on (" /canspeed" , HTTP_POST , handleCanSpeed);
833+
793834 server.begin ();
794835 wifiActive = true ;
795836 Serial.println (" Web server aktif." );
796837 Serial.printf (" WiFi AP: %s\n " , ssid);
838+
797839 Serial.printf (" AP IP Address: %s\n " , WiFi.softAPIP ().toString ().c_str ());
798840 Serial.printf (" Access web server at: http://%s/\n " , WiFi.softAPIP ().toString ().c_str ());
799841 esp_wifi_set_max_tx_power (78 );
@@ -884,6 +926,29 @@ void handleToggle()
884926 }
885927}
886928
929+ void handleCanSpeed () {
930+ if (server.method () == HTTP_GET ) {
931+ char buf[16 ];
932+ snprintf (buf, sizeof (buf), " %u" , getCanSpeed ());
933+ server.send (200 , " text/plain" , buf);
934+ } else if (server.method () == HTTP_POST ) {
935+ if (server.hasArg (" speed" )) {
936+ uint32_t speed = server.arg (" speed" ).toInt ();
937+ if (speed == 500000 || speed == 1000000 ) {
938+ setCanSpeed (speed);
939+ server.send (200 , " text/plain" , " OK" );
940+ Serial.printf (" CAN speed set to %u bps via webserver\n " , speed);
941+ } else {
942+ server.send (400 , " text/plain" , " Invalid speed" );
943+ }
944+ } else {
945+ server.send (400 , " text/plain" , " Missing speed param" );
946+ }
947+ } else {
948+ server.send (405 , " text/plain" , " Method Not Allowed" );
949+ }
950+ }
951+
887952void handleWebServerClients ()
888953{
889954 static uint32_t lastClientCheck = 0 ;
0 commit comments