42IpAddress serverIp = IpAddress(192, 168, 0, 123);
48#define MAX_PACKET_LENGTH 100
50unsigned char packetReceived[MAX_PACKET_LENGTH];
58 ConnectorUsb.
Mode(Connector::USB_CDC);
59 ConnectorUsb.
Speed(9600);
61 uint32_t timeout = 5000;
63 while (!ConnectorUsb &&
Milliseconds() - startTime < timeout) {
70 ConnectorIO0.
Mode(Connector::OUTPUT_DIGITAL);
74 ConnectorUsb.
SendLine(
"The Ethernet cable is unplugged...");
97 IpAddress ip = IpAddress(192, 168, 0, 103);
112 EthernetTcpClient client;
115 if (!client.Connect(serverIp, PORT_NUM)) {
129 if(!client.Connected()){
133 uint32_t delay = 1000;
134 if (!client.Connect(serverIp, PORT_NUM)) {
145 if( client.Send(
"Hello server") >0)
148 bool receivedMessage =
false;
151 uint32_t delay = 1000;
154 if (client.Read(packetReceived, MAX_PACKET_LENGTH) > 0)
156 receivedMessage =
true;
160 for(
int i=0; i<MAX_PACKET_LENGTH; i++){
161 packetReceived[i]=NULL;
167 if (!receivedMessage){
ClearCore timing profiling utility functions.
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287
uint32_t Milliseconds(void)
Number of milliseconds since the ClearCore was initialized.
int16_t State() override
Get connector's last sampled digital value.
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition DigitalInOutAnalogOut.h:70
volatile const bool & PhyLinkActive()
Check the link status from the PHY.
Definition EthernetManager.h:136
IpAddress LocalIp()
Get the local IP address.
void Refresh()
Perform any necessary periodic Ethernet and LwIP updates.
bool DhcpBegin()
Set up DHCP connection to retrieve local IP.
void Setup()
Setup LwIP with the local network interface.
bool SendLine()
Send carriage return and newline characters.
Definition ISerial.h:162
virtual bool Speed(uint32_t bitsPerSecond)=0
Change the baud rate for the port.
bool Send(const char *buffer, size_t bufferSize)
Send the array of characters out the port.
Definition ISerial.h:173
char * StringValue()
Returns a string representation of the IP Address.
Definition IpAddress.h:96
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition SerialUsb.h:210
DigitalInOutAnalogOut ConnectorIO0
IO-0 connector instance.
SerialUsb ConnectorUsb
USB connector instance.
EthernetManager & EthernetMgr
Ethernet manager.