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: ConfigFile EthernetInterface mbed-rtos mbed
Fork of S05APP3 by
Diff: main.cpp
- Revision:
- 0:ec23a7ae804c
- Child:
- 1:ceb3f8ba8793
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 09 04:24:55 2017 +0000 @@ -0,0 +1,61 @@ +#include "EthernetInterface.h" +#include "ConfigFile.h" +#include "mbed.h" + +//To set the xbee +Serial xbee(p13, p14); +DigitalOut reset(p8); + +//Socket Buffer +char buffer[50]; +char serverAddrvalue[32]; + +//Read the config file +void readConfigFile() +{ + LocalFileSystem local("local"); + ConfigFile cfg; + char *serverAddr = "serverAddr"; + if (!cfg.read("/local/input.cfg")) error("Failure to read a configuration file.\n"); + else cfg.getValue(serverAddr, &serverAddrvalue[0], sizeof(serverAddrvalue)); +} + +//Init RJ45 and use DHCP +void initRJ45() +{ + EthernetInterface rj45; + rj45.init(); + rj45.connect(); +} + +void initSocket() +{ + //Init Socket + TCPSocketConnection sock; + sock.connect(serverAddrvalue, 502); + + sprintf (buffer, serverAddrvalue); + sock.send_all(buffer, sizeof(buffer)-1); + + int repSize; + while (true) { + repSize = sock.receive(buffer, sizeof(buffer)-1); + if (repSize <= 0) { + printf("Error"); + sock.close(); + break; + } + buffer[repSize] = '\0'; + printf("Received %d chars from server:\n%s\n", repSize, buffer); + } +} + +int main() { + + readConfigFile(); + initRJ45(); + initSocket(); + + while(1) {} +} +