Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Power Lifting Lever Belt
SkullVamp
Updated:
Saturday at 10:32 PM
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Saturday at 3:55 PM
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Thursday at 2:23 PM
Ad icon
Wechat qr verification
Pawan2005
Updated:
Thursday at 1:28 AM
🚀 GOOGLE AI PRO 18 MONTHS ACTIVATION 🚀
sayuru bandara
Updated:
Jun 10, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
Computers & Internet
Problems and Troubleshooting
C# Websocket for IoT
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="buddhikakgsl" data-source="post: 26118692" data-attributes="member: 409596"><p><span style="font-size: 15px">මම ESP32 device එකකින් websocket හරහා browser එකට sensor data send කරනව. මට ඔනි මේ reading ටික කෙලින්ම Winform app එකකට යවන්න මෙක කරන්නෙ කොහොමද.</span></p><p></p><p>මේක තමයි දැනට කරන code එක.</p><p></p><p>//============================</p><p>#include <WiFi.h></p><p>#include <WebServer.h></p><p>#include <WebSocketsServer.h></p><p>#include <driver/i2s.h></p><p></p><p>const i2s_port_t I2S_PORT = I2S_NUM_0;</p><p>const char* ssid = "SSID";</p><p>const char* password = "PWD";</p><p></p><p>WebServer server(80);</p><p>WebSocketsServer webSocket = WebSocketsServer(81);</p><p></p><p>String JSONtxt;</p><p></p><p>#include "webpage.h"</p><p>void handleRoot()</p><p>{</p><p> server.send(200,"text/html", webpageCont);</p><p>}</p><p>void setup()</p><p>{</p><p>Serial.begin(115200);</p><p></p><p>const i2s_config_t i2s_config = {</p><p> // configuration </p><p> };</p><p></p><p>const i2s_pin_config_t pin_config = {</p><p> //pin configuration</p><p>}</p><p></p><p>server.on("/", handleRoot);</p><p>server.begin(); webSocket.begin();</p><p></p><p></p><p>void loop() </p><p>{</p><p>webSocket.loop(); server.handleClient();</p><p></p><p>int32_t sample = 0;</p><p>int bytes_read = i2s_pop_sample(I2S_PORT, (char *)&sample, portMAX_DELAY); // no timeout</p><p>if (bytes_read > 0) {</p><p></p><p>String sampleString = String(sample);</p><p></p><p>JSONtxt = "{\"sample\":\""+sampleString+"\"}";</p><p>webSocket.broadcastTXT(JSONtxt);</p><p></p><p></p><p>//============================</p><p>webpage.h</p><p>//============================</p><p></p><p>const char webpageCont[] PROGMEM = </p><p>R"=====(</p><p><!DOCTYPE HTML></p><p><html></p><p><title>ESP32 WebSocket Server</title></p><p><!---------------------------CSS--------------------------></p><p><style></p><p> </p><p> body {background-color:rgba(128,128,128,0.322); font-family:calibri}</p><p> h1 {font-size: 40px; color: black; text-align: center}</p><p> h2 {font-size: 30px; color: blue}</p><p> </p><p> div.h1 {background-color: whitesmoke;}</p><p></style></p><p><!--------------------------HTML--------------------------></p><p><body></p><p> <h1><div class="h1">ESP32 WebSocket Server</div></h1></p><p> <h2></p><p> Level: <span style="color:rgb(216, 3, 3)" id="sample"></span> </p><p> </h2></p><p> </body></p><p><!----------------------JavaScript------------------------></p><p><script></p><p> InitWebSocket()</p><p> function InitWebSocket()</p><p> {</p><p> websock = new WebSocket('ws://'+window.location.hostname+':81/');</p><p> websock.onmessage=function(evt)</p><p> {</p><p> JSONobj = JSON.parse(evt.data);</p><p> document.getElementById('sample').innerHTML = JSONobj.sample;</p><p> var sample = parseInt(JSONobj.sample);</p><p> </p><p> }</p><p> }</p><p></script></p><p></html></p><p>)=====";</p><hr /><p>bump</p><p>------ <span style="font-size: 10px">Post added on [DATETIME="UT"]1612837458[/DATETIME]</span></p></blockquote><p></p>
[QUOTE="buddhikakgsl, post: 26118692, member: 409596"] [SIZE=4]මම ESP32 device එකකින් websocket හරහා browser එකට sensor data send කරනව. මට ඔනි මේ reading ටික කෙලින්ම Winform app එකකට යවන්න මෙක කරන්නෙ කොහොමද.[/SIZE] මේක තමයි දැනට කරන code එක. //============================ #include <WiFi.h> #include <WebServer.h> #include <WebSocketsServer.h> #include <driver/i2s.h> const i2s_port_t I2S_PORT = I2S_NUM_0; const char* ssid = "SSID"; const char* password = "PWD"; WebServer server(80); WebSocketsServer webSocket = WebSocketsServer(81); String JSONtxt; #include "webpage.h" void handleRoot() { server.send(200,"text/html", webpageCont); } void setup() { Serial.begin(115200); const i2s_config_t i2s_config = { // configuration }; const i2s_pin_config_t pin_config = { //pin configuration } server.on("/", handleRoot); server.begin(); webSocket.begin(); void loop() { webSocket.loop(); server.handleClient(); int32_t sample = 0; int bytes_read = i2s_pop_sample(I2S_PORT, (char *)&sample, portMAX_DELAY); // no timeout if (bytes_read > 0) { String sampleString = String(sample); JSONtxt = "{\"sample\":\""+sampleString+"\"}"; webSocket.broadcastTXT(JSONtxt); //============================ webpage.h //============================ const char webpageCont[] PROGMEM = R"=====( <!DOCTYPE HTML> <html> <title>ESP32 WebSocket Server</title> <!---------------------------CSS--------------------------> <style> body {background-color:rgba(128,128,128,0.322); font-family:calibri} h1 {font-size: 40px; color: black; text-align: center} h2 {font-size: 30px; color: blue} div.h1 {background-color: whitesmoke;} </style> <!--------------------------HTML--------------------------> <body> <h1><div class="h1">ESP32 WebSocket Server</div></h1> <h2> Level: <span style="color:rgb(216, 3, 3)" id="sample"></span> </h2> </body> <!----------------------JavaScript------------------------> <script> InitWebSocket() function InitWebSocket() { websock = new WebSocket('ws://'+window.location.hostname+':81/'); websock.onmessage=function(evt) { JSONobj = JSON.parse(evt.data); document.getElementById('sample').innerHTML = JSONobj.sample; var sample = parseInt(JSONobj.sample); } } </script> </html> )====="; [HR][/HR] bump ------ [SIZE=2]Post added on [DATETIME="UT"]1612837458[/DATETIME][/SIZE] [/QUOTE]
Insert quotes…
Verification
Hata thunen beduwama keeyada? (60 bedeema thuna)
Post reply
Top
Bottom