Weather control switch for connected day. NXP LPC 1768 module. Ethernet connectivity.
Dependencies: EthernetInterface mbed-rtos mbed nanoservice_client_1_12
Fork of Trenton_Switch_LPC1768_WIFLY by
Diff: main.cpp
- Revision:
- 22:b361f7ae0508
- Parent:
- 20:c35b8700d5b2
- Child:
- 25:cb16c5248769
--- a/main.cpp Wed Jul 23 10:04:03 2014 +0000 +++ b/main.cpp Wed Aug 13 09:56:11 2014 +0000 @@ -14,35 +14,64 @@ * limitations under the License. */ #include "mbed.h" -#include "WiflyInterface.h" +#include "EthernetInterface.h" #include "main.h" #include "nsdl_support.h" #include "switch.h" //Serial pc(USBTX, USBRX); -/* wifly object where: -* - p9 and p10 are for the serial communication -* - p25 is for the reset pin -* - p26 is for the connection status -* - "mbed" is the ssid of the network -* - "password" is the password -* - WPA is the security +// **************************************************************************** +// Configuration section + +// Ethernet configuration +/* Define this to enable DHCP, otherwise manual address configuration is used */ +#define DHCP + +/* Manual IP configurations, if DHCP not defined */ +#define IP "10.45.0.206" +#define MASK "255.255.255.0" +#define GW "10.45.0.1" + +// **************************************************************************** +// Ethernet initialization + +EthernetInterface eth; + +static void ethernet_init() +{ + char mbed_uid[33]; // for creating unique name for the board + + /* Initialize network */ +#ifdef DHCP + printf("DHCP in use\r\n"); + eth.init(); +#else + eth.init(IP, MASK, GW); +#endif + if(eth.connect(30000) == 0) + printf("Connect OK\n\r"); +/* + mbed_interface_uid(mbed_uid); + mbed_uid[32] = '\0'; + strncat(endpoint_name, mbed_uid + 27, 15 - strlen(endpoint_name)); + + lcd.locate(0,11); + lcd.printf("IP:%s", eth.getIPAddress()); */ -WiflyInterface wifly(p9, p10, p25, p26, SSID, AP_KEY, WPA); -//WiflyInterface wifly(PTE16, PTE17, PTD4, PTD2, SSID, AP_KEY, WPA); //KL46Z + printf("IP Address:%s ", eth.getIPAddress()); +} // NSP configuration /* Change this IP address to that of your NanoService Platform installation */ Endpoint nsp; UDPSocket server; + //extern TCPSocketConnection server; char endpoint_name[] = {"switch"}; uint8_t ep_type[] = {"mbed_LPC1768"}; uint8_t lifetime_ptr[] = {"86400"}; -//static const char* NSP_ADDRESS = "208.111.39.209"; /* demo NSP, web interface at http://nanoservice-demo.mbed.org*/ -//static const char* NSP_ADDRESS = "10.2.131.119"; /* aseserver NSP, */ static const char* NSP_ADDRESS = "192.168.1.10"; /* Trenton BBB NSP */ static const int NSP_PORT = 5683; @@ -192,16 +221,9 @@ * \return int */ int main() { - //factory reset Wifly - wifly.reset(); - printf("\nFactory Reset\r\n"); - //reboot wifly - bool success = wifly.reboot(); - printf("Reboot: %d\r\n", success); //success = 1 -> successful process - printf("Initialising Wifly...\r\n"); - wifly.init(); // use DHCP - while (!wifly.connect()); // join the network - printf("IP Address is %s\r\n", wifly.getIPAddress()); + printf("Initialising Ethernet...\r\n"); + // Initialize Ethernet interface first + ethernet_init(); // Bind the socket and configure NSP settings nsp_connect();