HAPSRG / Mbed OS UDP_Client_0003

Dependencies:   UsaClient

main.cpp

Committer:
cocorlow
Date:
2021-10-28
Revision:
1:c050a4297deb
Parent:
0:4d6a8970674c
Child:
2:1b4bba79cd29

File content as of revision 1:c050a4297deb:

#include "mbed.h"
#include "EthernetInterface.h"
#include "UsaClient.hpp"

EthernetInterface net;
DigitalIn button(PC_13);

int main()
{
    SocketAddress sockAddr;
    if (net.connect() != 0)
    {
        printf("a");
        return -1;
    }
    net.get_ip_address(&sockAddr);
    printf("IP: %s\r\n", sockAddr.get_ip_address() ? sockAddr.get_ip_address() : "No IP");
    
    
    UsaClient udp(&net, "192.168.251.42", 10000); // server IP address, Port number
    uint8_t send[6] = {1, 4, 9, 16, 25, 0};
    uint8_t recv[6];
    
    while (1)
    {
        if (button)
        {
            send[5] += 1;
            udp.Write(2, send, 6);
        }
        udp.Read(2, recv, 6);
        printf("%3d, %3d, %3d, %3d, %3d, %3d\r\n", recv[0], recv[1], recv[2], recv[3], recv[4], recv[5]);
        ThisThread::sleep_for(chrono::milliseconds(100));
    }
}