Commit 2b1cf918 authored by Florence Guitton's avatar Florence Guitton

use ajax

parent d4530214
allsky.jpg

105 KB | W: | H:

allsky.jpg

44.8 KB | W: | H:

allsky.jpg
allsky.jpg
allsky.jpg
allsky.jpg
  • 2-up
  • Swipe
  • Onion skin
<?php
error_reporting(E_ALL);
//PASSER REQUETE
//if( $_GET["pointage"] ){
//$in='$'.'pointage!';
// getActions($in);
//}
if(isset($_GET['pointer'])) {
//format de la page html a afficher
echo "param ok";
$in='$'.'pointage!';
echo "<p>client!!!".$action."</p>";
function getActions($in){
//socket
/* port du service */
$service_port = 10001;
/* Lit l'adresse IP du serveur de destination */
//$address = gethostbyname('bbking.oca.eu');
/* Crée un socket TCP/IP. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket == false) {
echo "socket_create() a échoué : raison : " . socket_strerror(socket_last_error()) . "<br>";
echo "socket_create() a échoué : raison : " . socket_strerror(socket_last_error()) . "<br>";
}
$result = socket_connect($socket, '127.0.0.1', $service_port);
if ($socket == false) {
echo "socket_connect() a échoué : raison : ($result) " . socket_strerror(socket_last_error($socket)) . "<br>";
//echo "socket_connect() a échoué : raison : ($result) " . socket_strerror(socket_last_error($socket)) . "<br>";
}
socket_write($socket, $in, 10);
$out = socket_read($socket, 50);
return $out;
}
echo "client:".$out."!";
//}
//else
//echo "client ko";
}
else{
echo "<p> valeur inconnue</p>";
}
?>
......@@ -9,10 +9,7 @@ include "status_meteo.php";
include "get_pictures_allsky.php";
include "graph_data.php";
include "image.php";
include "client.php";
//include "client.php";
?>
......@@ -32,6 +29,7 @@ include "client.php";
<br><br></center>
<center>
<table border>
<tr>
......@@ -86,29 +84,27 @@ include "client.php";
<td colspan=2> <!-- 2 colonnes -->
<center>IMAGES</center>
<?php $images=getFiles('/home/guitton/');
?>
<center>
<?php echo '<a href='.$images[0].'><img src='.$images[0].' alt="<?php echo $title1 ?>" style="width:200px;height:200px;"></a>'; ?>
<a href="http://meteospace-c.oca.eu/picardsol/quick.png"><img src="../picardsol/quick.png" style="width:200px;height:200px;"></a>
</center>
</td></tr>
<tr><td colspan=2>
<center>
<?php echo '<a href='.$images[1].'><img src='.$images[1].' alt="<?php echo $title1 ?>" style="width:200px;height:200px;"></a>'; ?>
<a href="http://meteospace-c.oca.eu/picardsol/last_v2.png"><img src="../picardsol/last_v2.png" style="width:200px;height:200px;"></a>
</center>
</td></tr>
<tr><td colspan=2>
<center>
<?php echo '<a href='.$images[2].'><img src='.$images[2].' alt="<?php echo $title1 ?>" style="width:200px;height:200px;"></a>'; ?>
<a href="http://meteospace-c.oca.eu/picardsol/mammar_quicklook.png"><img src="../picardsol/mammar_quicklook.png" style="width:200px;height:200px;"></a>
</center>
</td></tr>
<tr>
<td><center>OBSERVATIONS</center></td>
<td><center>OBSERVATIONS</center>
<xml id="fichierxml" src="METEOSPACE-_config.xml"></xml>
<span datafld="FIELD"></span>
</td>
<td><center>log</center>
......@@ -156,56 +152,57 @@ else{
$info2=explode(" ",$chaine2[1]);
$number2=substr(explode(" ",$info2[count($info2)-1])[0],-3,2);//pas propre
if ($number2<90){
echo '<p style="Color:green" >disque: '.explode(" ",explode(" ",$chaine2[1])[4])[2].', occupation: '.$number2.'%</p>';
echo '<p style="Color:green" >disque: '.$info2[0].', occupation: '.$number2.'%</p>';
}
else{
echo '<p style="Color:red">disque: '.explode(" ",explode(" ",$chaine2[1])[4])[2].', occupation: '.$number2.'%</p>';
echo '<p style="Color:red">disque: '.$info2[0].', occupation: '.$number2.'%</p>';
}
?>
</td></tr>
<tr>
<!-- definir plus precessisement ce que l on y met: bouton pour selectionner requete? quel affichage ?... -->
<tr>
<td style="border:2px solid red" ><center>actions</center>
<table>
<tr >
<td><center>ACTIONS OBS</center></td>
<td style="border:2px solid black"><center>ACTIONS OBS</center>
<button type="button" onclick="actions()">pointer</button>
<!-- <input type="submit" name="pointer" value="pointer" />
<input type="button" name="pointer" value="suivre" /> -->
<script>
function actions(){
var xhttp = new XMLHttpRequest();
}
</script>
</td>
<!-- spliter la réponse pour avoir la led a allumer et sa couleur -->
<td><center>ACTIONS TOIT</center></td>
<td style="border:2px solid black"><center>ACTIONS TOIT</center>
<input type="button" name="pointer" value="ouvir" />
<input type="button" name="pointer" value="fermer" />
</td>
</tr>
<tr>
<td>
<!-- checkbox? -->
<form action='index.php' method='post' >
<input type="hidden" name="bouton" value="pointage" />
<input type="submit" name="submit" id="submit" value="POINTER"> <!-- :<input type="image" src="red.bmp"> -->
</form>
<?php
if ($_POST["bouton"]){
$out=getActions('$'.'pointage!');
if (strcmp($out,"KO")==0)
{echo '<input type="image" src="red.bmp">'; }
else
{echo '<input type="image" src="green.bmp">'; }
//disparait au refresh de la page!!!!
}
?>
</td>
<td>une autre action</td>
</tr>
</table>
</td>
</tr>
<td><center>STATUS COM</center></td>
<td><center>STATUS COM</center>
<?php
echo "reponse du serveur: ".$out."!"; ?>
<!-- ecrire les reponses dans un fichier pour afficher toutes les lignes? sinon perdu au refresh -->
</td>
</tr>
<!--
......
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
include "gdimm_status.php";
include "status_allsky.php";
include "status_meteo.php";
include "get_pictures_allsky.php";
include "graph_data.php";
include "image.php";
?>
<head>
<!-- <meta> tags always go inside the <head> element
take them out as you’re able, to reduce page weight and load times
-->
<meta name="viewport" content="width=device-width"/>
<link rel="stylesheet" type="text/css" href="cats.css">
<link rel="stylesheet" type="text/css" href="cats_gdimm.css">
<link rel="stylesheet" type="text/css" href="cats_allsky.css">
<script type='text/javascript'>
function getXhttp(){
var xhttp = null;
if(window.XMLHttpRequest) <!-- Firefox et autres -->
xhttp = new XMLHttpRequest();
else if(window.ActiveXObject){ <!-- Internet Explorer -->
try {
xhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else { <!-- XMLHttpRequest non supporté par le navigateur -->
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
xhttp = false;
}
return xhttp;
}
function loadDoc() {
//xhttp = new XMLHttpRequest();
var xhttp = getXhttp();
<!--affecte une fonction a nous qui sera exécutée à chaque "changement d'état" de notre objet. -->
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
//reload picture
$(document).ready(
function() {
setInterval(function() {
var myImageElement = document.getElementById('photo');
//myImageElement.setAttribute("src", 'allsky.jpg');
//otherwise use picture in cache
myImageElement.src = '../picardsol/quick.png?rand=' + Math.random();
console.log(myImageElement);
}, 10000);
});
// });
</script>
</head>
<body>
<!-- get/post data from/to Server using pure JavaScript
lecture asynchrone des ressources, requête au serveur et attente du retour
-->
<h1>The XMLHttpRequest Object</h1>
<p id="demo">Let AJAX change this text.</p>
<button type="button" onclick="loadDoc()">Change Content</button>
<div id="image">
<a href="http://meteospace-c.oca.eu/picardsol/quick.png"><img src="../picardsol/quick.png" style="width:200px;height:200px;"></a>
</div>
<td><center>log</center>
<?php
$path='/METEOSPACE-C-DATA/picardsol/DATA/journaux_pilotage_sodism2/';
exec('ls -ltr '.$path, $chaine) ;
$info=explode(" ",$chaine[count($chaine)-1]);
//echo '<p> le fichier :'.$path.$info[count($info)-1].'</p>';
exec('tail -10 '.$path.$info[count($info)-1], $chaine1) ;
for ($i=0; $i<count($chaine1); $i++){
echo '<font color="green" >'.iconv("ISO-8859-1", "UTF-8", $chaine1[$i]).'<br></font>';
}
$chaine="";
$info="";
?>
</td>
</body>
\ No newline at end of file
#include <cstdio>
#include <cstdlib>
#include <cerrno>
#include <ctime>
#include <string.h>
#include <string>
#include <sys/socket.h>
#include <arpa/inet.h> //inet_addr
#include <unistd.h> //write
#include <stdbool.h>
#include <pthread.h>
using namespace std;
////////////////////////
///////////////////////////////////////////
//
// compiler par :
// g++ -I ./ -c -o getparam.o getparam.cpp
// gcc -Wall serveur_acquisition.cpp getparam.o -o serveur_acquisition -fno-builtin -lpthread
//g++ -I ./ -Wall serveur_acquisition.cpp getparam.cpp -o serveur_acquisition -fno-builtin -lpthread
///////////////////////////////////////////
#define PORT 10001 // The first 1000 ports are reserved for specific applications on linux
#define NUM_THREADS 1
struct thread_data {
int thread_id;
char *message;
};
//extern string toit;
extern string acquisitions;
extern string cameras;
extern string alim;
extern string plan;
extern string pointage;
extern string image;
// lecture des parametres :
extern int getparam();
///////////////////////
// Variables globales:
time_t t;
struct tm t_m;
int client_sock, read_size, hms_fincor, hh, mn;
bool mess1, mess2;
bool breakreadwrite;
FILE *trace;
int status;
///////////////////////////////////////////////////////
void *readsocket(void *threadid){
//
int n1;
char buffer[256];
// char buffertrace[256];
while (1) {
bzero(buffer, 256);
read_size = recv(client_sock, buffer, 256, 0);
if (read_size > 0 ){
t = time(NULL);
t_m = *localtime(&t);
hms_fincor = t_m.tm_hour*60+t_m.tm_min;
printf("Message recu = %s (hh=%d mn=%d %d sec)\n",
buffer, t_m.tm_hour, t_m.tm_min, t_m.tm_sec) ;
fflush(stdout);
getparam(); // lecture des etats
/* messages attendus:
$pointage
$stopAcquisition
$changePlan
$imageAcquisition
$cameraOn (pluriel: donner numero ou toutes ensembles?. plusieures cameras?)
$cameraOff
$cameraEtat
$alimOn
$alimOff
*/
n1=strncmp(buffer, "$pointage!", 10); //$pointage! la commande envoyée
if (n1 == 0) {
fflush(stdout);
bzero(buffer, 256);//erases data
sprintf(buffer, "%s", pointage.c_str()); //besoin de connaitre la requete de depart?
status = write(client_sock, buffer, strlen(buffer));
} else {
n1=strncmp(buffer, "$stopAcquisition!", 17);
if (n1 == 0) {
fflush(stdout);
bzero(buffer, 256);
sprintf(buffer, "%s",acquisitions.c_str());
status = write(client_sock, buffer, strlen(buffer));
} else {
n1=strncmp(buffer, "$changePlan!", 12);
if (n1 == 0) {
fflush(stdout);
bzero(buffer, 256);
sprintf(buffer, "%s", plan.c_str());
status = write(client_sock, buffer, strlen(buffer));
} else {
n1=strncmp(buffer, "$imageAcquisition!", 18);
if (n1 == 0) {
fflush(stdout);
bzero(buffer, 256);
sprintf(buffer, "$imageAcquisition:%s", image.c_str());
status = write(client_sock, buffer, strlen(buffer));
} else {
n1=strncmp(buffer, "$cameraOff!", 11);
if (n1 == 0) {
fflush(stdout);
bzero(buffer, 256);
sprintf(buffer, "$cameraOff:%s!", cameras.c_str());
status = write(client_sock, buffer, strlen(buffer));
} else {
n1=strncmp(buffer, "$cameraOn!", 10);
if (n1 == 0) {
fflush(stdout);
bzero(buffer, 256);
sprintf(buffer, "$cameraOn:%s!", cameras.c_str());
status = write(client_sock, buffer, strlen(buffer));
} else {
n1=strncmp(buffer, "$cameraEtat!", 12);
if (n1 == 0) {
fflush(stdout);
bzero(buffer, 256);
sprintf(buffer, "$cameraEtat:%s!", cameras.c_str());
status = write(client_sock, buffer, strlen(buffer));
} else {
n1=strncmp(buffer, "$alimOn!", 8);
if (n1 == 0) {
fflush(stdout);
bzero(buffer, 256);
sprintf(buffer, "$alimOn:%s!", alim.c_str());
status = write(client_sock, buffer, strlen(buffer));
} else {
n1=strncmp(buffer, "$alimOff!", 9);
if (n1 == 0) {
fflush(stdout);
bzero(buffer, 256);
sprintf(buffer, "$alimOff:%s!", alim.c_str());
status = write(client_sock, buffer, strlen(buffer));
} else {
printf("message non reconnu %s\n", buffer);
fflush(stdout);
bzero(buffer, 256);
sprintf(buffer, "$notcommand!");
status = write(client_sock, buffer, strlen(buffer));
}
}
}
}
}
}
}
}
}
}
else {
breakreadwrite=true;
printf("Connection arretee de la part de l'automate' %d\n", read_size);
fflush(stdout);
close(client_sock);
pthread_exit(NULL);
}
} // while (1)
} // fin de readsocket
////////////////////////////////////////////
//
////////////////////////////////////////////
////////////////////////////////////////////
int main(int argc, char *argv[]) {
int socket_desc, c;
struct sockaddr_in server, client;
char buffer[256];
/* size_t buffer_size;
char * word;
char * pch1;
char * pch2 ;*/
int status;
int hh,mn;
// bool fichtrace, findujour;
//////////////////////////////
pthread_t threads[NUM_THREADS];
struct thread_data td[NUM_THREADS];
//////////////////////////////////
t = time(NULL);
t_m = *localtime(&t);
printf("Debut de serveur acquisition a %dh%dmn%ds (%d/%d/%d) \n",
t_m.tm_hour, t_m.tm_min, t_m.tm_sec, t_m.tm_mday, t_m.tm_mon+1, t_m.tm_year+1900);
fflush(stdout);
status=0;
t = time(NULL);
t_m = *localtime(&t);
hh=t_m.tm_hour;
mn=t_m.tm_min;
fflush(stdout);
/////////////////////////////////////////////
//Create socket
socket_desc = socket(AF_INET, SOCK_STREAM, 0);
if (socket_desc == -1) {
perror(strerror(errno));
return(-1);
}
printf("Socket cree\n");
fflush(stdout);
t_m = *localtime(&t);
//Preparation structure sockaddr_in
server.sin_family = AF_INET;
server.sin_addr.s_addr = htonl(INADDR_ANY);// INADDR_ANY;
server.sin_port = htons(PORT );
if( bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0){
//print the error message
perror(strerror(errno));
fflush(stdout);
return(-1);
}
/////////////////////////////////////////////////////////
while ( 0 == 0 ) {
// On attend la connection du client :
/////////////////////////////////////////////////////////
breakreadwrite=false;
listen(socket_desc, 3);
printf("Waiting for incoming connections...\n");
fflush(stdout);
c = sizeof(struct sockaddr_in);
client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c);
if (client_sock < 0){
perror(strerror(errno));
return 1;
}
t = time(NULL);
t_m = *localtime(&t);
hh = t_m.tm_hour;
mn = t_m.tm_min;
printf("Client connected %dh %dmn (%d/%d/%d) \n", hh, mn,
t_m.tm_mday, t_m.tm_mon+1, t_m.tm_year+1900);
fflush(stdout);
sprintf(buffer, "$CONNECTIONOK!");
status=write(client_sock, buffer, strlen(buffer));
/* bzero(buffer, 256);
read_size = recv(client_sock, buffer, 256, 0);
if (read_size > 0 ){
printf("Message recu = %s \n", buffer) ;
fflush(stdout);
}*/
/////////////////////////////////////////////////////////
// Le client est connecte, on gere les messages de correction dans la boucle qui suit
// lancement du thread de lecture sur le socket
td[0].thread_id = 0;
pthread_create(&threads[0], NULL, readsocket, (void *)&td[0]);
while (( 1 != 0 ) && (breakreadwrite == false)) {
/////////////////////////////////////////////////////////
//
if (status < 0) {
breakreadwrite=true;
}
} // fin de while ( 1 != 0 ) && (breakreadwrite == false)
sleep(10);
} // fin de while ( 0 == 0 )
return(0);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment