Hi,
I would like to get the value of a variable from an HTML page made with Jquery and websocket.
The value is coming from a slider hereafter the index.html file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>GPIO</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="stylesheet" href="assets/css/styles.css" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script src="assets/js/slider-jqueryui.js"></script>
<script src="/b4j_ws.js"></script>
</head>
<body>
<h1>Webb App GPIO</h1>
<p id="plog"></p>
<div id="maindiv">
<div id="slider"></div>
<p class="note">Current value: <span id="currentvalue">0</span></p>
</div>
<script>
//connect to the web socket when the page is ready.
$(function(){
var currentvalue = $('#currentvalue');
$("#slider").slider({
max: 100,
min: -100,
orientation :"vertical",
slide: function(event, ui) {
currentvalue.html(ui.value);
}
});
});
$( document ).ready(function() {
b4j_connect("/ws");
});
</script>
</body>
I've tried to use the variable currentvalue but I didn't have any value from it in the B4J program
Sub Class_Globals
Private ws AsWebSocket
Private currentvalue As JQueryElement
Private gp AsGpio_pwm
EndSub
Public Sub Initialize
gp.Initialize
EndSub
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
Log("Connecté")
ws = WebSocket1
EndSub
Private Sub currentvalue_Change (Params As Map)
Private cv1 As Future = currentvalue.GetVal
If IsNumber(cv1.Value) Then
gp.pwm_Write(1,cv1.Value)
EndIf
Log("CV1 :" & cv1)
EndSub
Private Sub WebSocket_Disconnected
Log("Déconnecté")
EndSub
Any help will be welcome
Luc
I would like to get the value of a variable from an HTML page made with Jquery and websocket.
The value is coming from a slider hereafter the index.html file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>GPIO</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="stylesheet" href="assets/css/styles.css" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script src="assets/js/slider-jqueryui.js"></script>
<script src="/b4j_ws.js"></script>
</head>
<body>
<h1>Webb App GPIO</h1>
<p id="plog"></p>
<div id="maindiv">
<div id="slider"></div>
<p class="note">Current value: <span id="currentvalue">0</span></p>
</div>
<script>
//connect to the web socket when the page is ready.
$(function(){
var currentvalue = $('#currentvalue');
$("#slider").slider({
max: 100,
min: -100,
orientation :"vertical",
slide: function(event, ui) {
currentvalue.html(ui.value);
}
});
});
$( document ).ready(function() {
b4j_connect("/ws");
});
</script>
</body>
I've tried to use the variable currentvalue but I didn't have any value from it in the B4J program
Sub Class_Globals
Private ws AsWebSocket
Private currentvalue As JQueryElement
Private gp AsGpio_pwm
EndSub
Public Sub Initialize
gp.Initialize
EndSub
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
Log("Connecté")
ws = WebSocket1
EndSub
Private Sub currentvalue_Change (Params As Map)
Private cv1 As Future = currentvalue.GetVal
If IsNumber(cv1.Value) Then
gp.pwm_Write(1,cv1.Value)
EndIf
Log("CV1 :" & cv1)
EndSub
Private Sub WebSocket_Disconnected
Log("Déconnecté")
EndSub
Any help will be welcome
Luc