it almost there!
I get a " 200" back from server and a "1" for transfer complete. But the count never shows up. Please, can someone suggest where my error is? here is my code and server script.
Please disregard above info on channel. I scrapped the original code and started fresh. This is the part of the channel that communicates with the server. Thanks!!!
here is request task:
<?xml version="1.0" encoding="utf-8" ?>
<component name="NumTransfer" extends="Task">
<script type="text/brightscript">
<![CDATA[
sub init()
print " in NumTransfer"
'Print " Pin is "m.global.NumViewers
m.top.functionName = "go3"
end sub
sub go3()
timeout% = 5000
roRequest = CreateObject("roURLTransfer")
roRequest.setUrl("http://test.com:8080/formprocessor.php")
print "In NumTransfer"
roPort = CreateObject("roMessagePort")
roRequest.setPort(roPort)
'roRequest.AddHeader("customMethod","numviewers")
'roRequest.EnableEncodings(true)
numviewers = m.global.NumViewers
customMethod = m.global.NumViewers
print "after setting the port"
sleep(2000)
if (roRequest.AsyncPostFromString("numviewers"))
roEvent = wait(timeout%, roRequest.GetPort())
print "roEvent " roEvent
print "numviewers =" numviewers
if type(roEvent) = "roUrlEvent"
str = roEvent.GetString()
int = roEvent.GetInt()
print "I am Transferring NumViewers"
print "roEvent.GetResponseCode()" roEvent.GetResponseCode()
print "str = " str
print "Int =" int
else if roEvent = invalid
roRequest.AsyncCancel() 'reset the connection on timeouts
print "Unknown"
else
print "roUrlTransfer::AsyncPostFromString(): unknown event"
endif
end if
DeviceInfo = CreateObject("roDeviceInfo")
IPAddr = DeviceInfo.getIPAddrs()
transfer = createObject("roUrlTransfer")
for each item in IPAddr
url = "http://" + IPAddr[item] + ":8060/keypress/Back"
transfer.setUrl(url)
transfer.PostFromString("")
url = "http://" + IPAddr[item] + ":8060/keypress/Back"
transfer.setUrl(url)
transfer.PostFromString("")
end for
end sub
]]>
</script>
</component>
next is server side script:
<?php
if(isset($_POST['customMethod']))
{
if(isset($_POST['numviewers']))
{
//Write the data to the file
$file = @fopen("count.txt", "r+");
if($file == false)
{
$file = fopen("count.txt", "w+");
}
$numViewers = $_POST['numviewers'];
$count = fgets($file);
if(($count == NULL) || ($count == ""))
{
//First entry in the file, just write to it
fwrite($file, $numViewers);
}
else
{
//Increment and then write to the file
$count = intval($count);
$count += $numViewers;
//Write back to the file
fclose($file);
$file = fopen("count.txt", "w+");
fwrite($file, $count);
}
fclose($file);
}
else
{
echo "<h2>Incorrect Call</h2>";
}
}
else
{
echo "<h2>Incorrect Call</h2>";
}
?>
here is web form that works with the above script:
<html>
<head>
<title>Input Number Of Viewers</title>
<script type="text/javascript">
function processForm()
{
//Get the number of viewers from the entry in the form
var numViewers = document.getElementById("numviewers").value;
if(numViewers.length > 0)
{
if(numViewers.match(/^[0-9]+$/g))
{
//Send the report to the php processor
var xmlhttp = new XMLHttpRequest();
var url = "formprocessor.php";
var data = new FormData();
data.append('customMethod', 'updateCounter');
data.append('numviewers', numViewers);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == XMLHttpRequest.DONE )
{
if (xmlhttp.status == 200)
{
window.location.href = "hls_progressive.html";
}
else if (xmlhttp.status == 400)
{
alert('There was an error 400');
}
else
{
alert('something else other than 200 was returned');
}
}
};
xmlhttp.open("POST", url, false);
xmlhttp.send(data);
}
}
return false;
}
</script>
<style>
.content
{
position: relative;
}
.formdiv
{
background: #CCC;
border: 1px solid #000;
left: 30%;
height: 150px;
margin: 0 auto;
padding: 0 0;
position: absolute;
text-align: center;
top: 50%;
transform: translateY(100%);
width: 40%;
}
</style>
</head>
<body>
<div class="content">
<div class="formdiv">
<form class="viewerform" method="POST" onsubmit="return processForm();">
<p>Please Enter the Number of People that will be Viewing this Meeting</p>
<label for="numviewers">Number Of Viewers: <input type="text" name="numviewers" id="numviewers"></label><br><br>
<span class="viewerformbuttonspan"><input type="submit" value="Submit"></span>
</form>
</div>
</div>
</body>
</html>
here is what my roku shows:
------ Compiling dev 'channel test' ------
------ Running dev 'channel test' main ------
Main Function 1 SGScreen
in NumTransfer
in Exiter1
in Init pindialogscene
In OnKey Event
key pressed =OK
in Show Dialog
m.valuepin in onKeyEvent =
m.top.dialog.buttonSelected in onKeyEvent = 0
In OnKey Event
In OnKey Event
in onKeyPress Function
M.TOP.DIALOG.PIN 2
m.global.NumViewers = 2
m.top.dialog.buttonSelected = 0
In NumTransfer
after setting the port
In OnKey Event
roEvent <h2>Incorrect Call</h2>
numviewers =2
I am Transferring NumViewers
roEvent.GetResponseCode() 200
str = <h2>Incorrect Call</h2>
Int = 1
In OnKey Event
In OnKey Event
key pressed =back
in Show Dialog
m.valuepin in onKeyEvent =
m.top.dialog.buttonSelected in onKeyEvent = 0
you are here! in SG Function Main not in While
button Selected: 0
In Exiter
In AppExiter
in SimpleVideoScene.xml onKeyEvent OK false