How do I receive messages from a GPS that uses GPRS via PHP?

Asked

Viewed 1,435 times

3

I have a Gosafe G91i device, a GPS device that sends your location from time to time to an IP and a port that I can set up. At the moment, are set IP and port of an online server (Orange gps-trace) and I would like to set to a server my, where I will format the data. At first, I don’t need performance, I just want to see if I can receive messages. What kind of PHP server should I use? Can it be some simple socket? Any suggestions? Thank you.

Follow the PHP code I have so far from the socket server, still not handling the messages.

  • 2

    404 - PHP code not found.

  • Edit: By chance it wasn’t the hehe code. I found the answer, I will answer my own question in a few moments.

2 answers

2

0

I managed to make the gps connect with this code how I treat and which variable captures the msgs?

require_once('/webserver/production/htdocs/assets/SocketServer.class.php'); // Include
    $server = new SocketServer("192.168.1.4",5008); //Criar um servidor de ligação para um determinado endereço IP e ouvir a porta 5008 para conexões
    $server->max_clients = 10; // Número de conexoes simultanea permitido
    $server->hook("CONNECT","handle_connect"); // Executa a funcao handle_connect cada vez que alguem se conecta
    $server->hook("INPUT","handle_input"); // Executar handle_input sempre que é enviado um texto para o servidor
    $server->infinite_loop(); // Inicia o servidor

    function handle_connect(&$server,&$client,$input){
        $this->db->query("insert into teste (texto) values ($input)"); ////////////////////////////////////////////////////////////////////////////////////////

        SocketServer::socket_write_smart($client->socket,"String? ","");
    }

    function handle_input(&$server,&$client,$input){// tratar entrada aq
        $trim = trim($input); // removendo espaços no texto de entrada

        //$this->db->query("insert into teste (texto) values ($trim)");///////////////////////////////////////////////////////////////////////////////////////////

        if(strtolower($trim) == "quit"){ // Parar servidor
            SocketServer::socket_write_smart($client->socket,"Ok! Goodbye..."); // Give the user a sad goodbye message, meany!
            $server->disconnect($client->server_clients_index); // Disconecta o cliente
            return;
        }

        $output = strrev($trim); // inverter string
        SocketServer::socket_write_smart($client->socket,$output); // envia o texto invertido
        SocketServer::socket_write_smart($client->socket,"String? ",""); // solicitar outro texto
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.