User Tools

Site Tools


crossplatformprogram

Creating a cross platform program

The first C# program seemed to work fine, but the catch was that it will only run on the Windows platform. So what to do?

At my workplace (Electronics Dept., Mercantec, Viborg, Denmark Teknisk Videncenter Elektronik) I teach Linux on the Raspberry Pi.

A Raspberry Pi equipped with a Nginx (engine x) Webserver, and some PHP could maybe do the trick ?

HTML
  <!DOCTYPE html>
  <html>
  <body>
  <?php
	function TurnOnSwede(){
		$server_ip = "192.168.1.101";
		$server_port = 2390;
		$beat_period = 5;
		$message = "OFF_NO1";
		if($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)){
			if( ! socket_sendto($socket, $message, strlen($message), 0, $server_ip, $server_port))
			{
				$errorcode = socket_last_error();
				$errormsg = socket_strerror($errorcode);
 
				die("Could not send data: [$errorcode] $errormsg \n");
				} else {
 
				}
 
		} else {
		print("can't create socket \n");
	}
    socket_close($sock);	}
 
	function TurnOffSwede(){
		$server_ip = "192.168.1.101";
	        $server_port = 2390;
	        $beat_period = 5;
		$message = "ON_NO1";
		if($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)){
			if( ! socket_sendto($socket, $message, strlen($message), 0, $server_ip, $server_port))
			{
				$errorcode = socket_last_error();
				$errormsg = socket_strerror($errorcode);
 
				die("Could not send data: [$errorcode] $errormsg \n");
				} else {
				}
 
		} else {
		print("can't create socket \n");
	}
        socket_close($sock);	}
 
	if ($_SERVER["REQUEST_METHOD"] == "POST") {
		if (isset($_POST["swedeon"])){
			TurnOnSwede();
			$_POST["swedeon"]=NULL;
		} else if (isset($_POST["swedeoff"])){
			TurnOffSwede();
			$_POST["swedeoff"]=NULL;
		}
		header("Location: {$_SERVER['HTTP_REFERER']}");
		exit;
	}
      ?>
     <h2><center>Home Control System Anlægsvej 7</center></h2>
     <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
     <center>  
     <input type="submit" class="btn-success" name="swedeon" value="The Swede on" style="height:50px;width:150px">  
     <input type="submit" class="btn-success" name="swedeoff" value="The Swede off" style="height:50px;width:150px">
     </center>  
     </form>
     </body>
     </html>
crossplatformprogram.txt · Last modified: 2018/01/05 07:47 by 185.22.75.1