Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface LM75B mbed-rtos mbed
Fork of communication by
Diff: master.cpp
- Revision:
- 0:52e944ca21ea
- Child:
- 1:550192b4ae8e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/master.cpp Tue Mar 13 09:40:51 2018 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+#include "master.h"
+#include <string.h>
+#include "EthernetInterface.h"
+
+Serial masterpc(USBTX, USBRX);
+
+void startMaster(const char* ip){
+ EthernetInterface eth;
+ eth.init(ip, "255.255.255.0", "192.168.0.1");
+ eth.connect();
+ masterpc.printf("ip = %s\n\r",eth.getIPAddress());
+ masterpc.printf("gateway = %s\n\r",eth.getGateway());
+ masterpc.printf("mask = %s\n\r",eth.getNetworkMask());
+ UDPSocket sock;
+
+ while(true){
+ char masterBuffer[512]={NULL};
+ masterpc.printf("type for request:\n\r");
+ for(int i = 0;i<512;i++){
+ char key = masterpc.getc();
+ if(key != 13){
+ masterpc.putc(key);
+ masterBuffer[i]=key;
+ }
+ else{
+ masterBuffer[i]='\0';
+ break;
+ }
+ }
+
+ char ipArray[14]={NULL};
+ masterpc.printf("insert ip address to send to:\n\r ");
+ for(int i = 0;i<14;i++){
+ char key = masterpc.getc();
+ if(key != 13){
+ masterpc.putc(key);
+ ipArray[i]=key;
+ }
+ else{
+ ipArray[i]='\0';
+ break;
+ }
+ }
+
+ sock.init();
+ const char *ECHO_SERVER_ADDRESS = ipArray;
+ Endpoint echo_server;
+ echo_server.set_address(ECHO_SERVER_ADDRESS,4000);
+ masterpc.printf("Sending \"%s\" to IPAddress :%s\n\r",masterBuffer,ECHO_SERVER_ADDRESS);
+ sock.sendTo(echo_server,masterBuffer,sizeof(masterBuffer));
+
+ int n = sock.receiveFrom(echo_server, masterBuffer, sizeof(masterBuffer));
+ masterBuffer[n] = '\0';
+ masterpc.printf("Received message from server: '%s'\n\r", masterBuffer);
+ sock.close();
+ }
+}
\ No newline at end of file
