módulo WIFI para comunicación de KL25Z midiendo corriente a través de una sonda amperimétrica con Android App neurGAI

Dependencies:   WiflyInterface mbed

Fork of wiflyServer by Gorka Bueno

main.cpp

Committer:
gbm
Date:
2016-02-28
Revision:
0:6d78e05ac19d
Child:
1:a340ab744f01

File content as of revision 0:6d78e05ac19d:

/*
// este es el programa a ejecutar en ordenador, como cliente (tutoriales de java): https://docs.oracle.com/javase/tutorial/networking/sockets/readingWriting.html

import java.io.*;
import java.net.*;

public class EchoClient {
    public static void main(String[] args) throws IOException {
        
        if (args.length != 2) {
            System.err.println(
                "Usage: java EchoClient <host name> <port number>");
            System.exit(1);
        }

        String hostName = args[0];
        int portNumber = Integer.parseInt(args[1]);

        try (
            Socket echoSocket = new Socket(hostName, portNumber);
            PrintWriter out =
                new PrintWriter(echoSocket.getOutputStream(), true);
            BufferedReader in =
                new BufferedReader(
                    new InputStreamReader(echoSocket.getInputStream()));
            BufferedReader stdIn =
                new BufferedReader(
                    new InputStreamReader(System.in))
        ) {
            String userInput;
            while ((userInput = stdIn.readLine()) != null) {
                out.println(userInput);
                System.out.println("echo: " + in.readLine());
            }
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host " + hostName);
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to " +
                hostName);
            System.err.println(e);
            System.exit(1);
        } 
    }
}

*/

#include "mbed.h"
#include "WiflyInterface.h"
 
#define ECHO_SERVER_PORT   7
 
WiflyInterface wifly(D3, D2, D5, LED1, "wifisarea", "wifi0712", WPA);
 
int main (void)
{
    printf("\nEmpezando...\n\r");
    wifly.init(); // use DHCP
    while (!wifly.connect()); // join the network
    printf("\nLa direccion IP es %s\n\r", wifly.getIPAddress());
 
    TCPSocketServer server;
    server.bind(ECHO_SERVER_PORT);
    server.listen();
 
    printf("\nEsperando conexion...\n");
    TCPSocketConnection client;
    server.accept(client);
    printf("\nServidor aceptado...\n");
    wait(1);    //si no se le mete un pequeño retardo, se queda colgado. También vale con el printf anterior
    
    char buffer[256];
    while (true) {
        int n = client.receive(buffer, sizeof(buffer));
        if (n <= 0) continue;
        buffer[n] = 0;
 
        client.send_all(buffer, n);
    }
}