Axeda AMMP sample code for the STMicro Nucleo-F103RB and W5500 Ethernet Shield

Dependencies:   W5500Interface mbed

Revision:
7:4ca0e960882a
Parent:
6:1f7647c5691a
--- a/main.cpp	Thu Jun 26 16:58:53 2014 +0000
+++ b/main.cpp	Sun May 17 13:45:00 2015 +0000
@@ -1,22 +1,41 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
- 
-EthernetInterface eth;
+
+#define USE_DHCP    1
+
+const char * IP_Addr    = "192.168.0.194";
+const char * IP_Subnet  = "255.255.255.0";
+const char * IP_Gateway = "192.168.0.1";
+unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56};
+
+#if defined(TARGET_NUCLEO_F103RB)
+    SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk
+    EthernetInterface eth(&spi, PB_6, PA_9); // spi, cs, reset
+
+    AnalogIn pot1(PA_0); // A0, Analog Input 0, F103RB
+    Serial pc(USBTX, USBRX);
+#else 
+    EthernetInterface eth;
  
-AnalogIn pot1(p19);
-AnalogIn pot2(p20);
+    AnalogIn pot1(p19);
+    AnalogIn pot2(p20);
+#endif
+
 TCPSocketConnection sock;
- 
+
+#if defined(TARGET_LPC1768)   
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
+#endif
  
 int main() 
 {
     
     char *MODEL = "mbed";
-    char *SERIAL_NUM = "SerialNumber"; 
+    //char *SERIAL_NUM = "SerialNumber";
+    char *SERIAL_NUM = "nlr__kevinlee_wiznet_co_kr___5138257";  
     float DEADBAND = 0.015;
     
     char* ip;
@@ -27,18 +46,27 @@
     char buffer[buffer_sz];  
     int returnCode = 0;
     
+#if defined(TARGET_LPC1768)     
     led1 = 1;
     led2 = 1;
     led3 = 1;
     led4 = 1;
+#endif
     
     printf("initializing Ethernet\r\n");
-    returnCode = eth.init(); //Use DHCP
+    //returnCode = eth.init(); //Use DHCP
+    #if USE_DHCP
+        returnCode = eth.init(MAC_Addr); //Use DHCP
+    #else
+        returnCode = eth.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway);
+    #endif
  
     if ( returnCode == 0 )
     {
         printf(" - Ethernet ready\r\n");
+#if defined(TARGET_LPC1768) 
         led1 = returnCode;
+#endif
     }
     else
     {
@@ -49,10 +77,14 @@
     printf("Ethernet.connecting \r\n");
     returnCode = eth.connect();
     printf(" - connecting returned %d \r\n", returnCode);
+#if defined(TARGET_LPC1768) 
     led2 = returnCode != -1 ? 0: 1;
+#endif
     printf("Trying to get IP address..\r\n");
     ip = eth.getIPAddress();
+#if defined(TARGET_LPC1768) 
     led3 = strlen(ip)<4 ? 1: 0;
+#endif
     printf("  -  IP address:%s\r\n", ip);
     
     float oil_level = 0.0;
@@ -63,7 +95,9 @@
     while(1) {
     
         oil_level = pot1.read();
+#if defined(TARGET_LPC1768)
         oil_level2=pot2.read();
+#endif
         
         if ( abs(oil_level - oldPotVal) < DEADBAND && abs(oil_level2 - oldPotVal2) < DEADBAND)
         {
@@ -71,11 +105,15 @@
         }
         else
         {
-            led4 = 1;
+            //led4 = 1;
             oldPotVal = oil_level;
+#if defined(TARGET_LPC1768)
             oldPotVal2 = oil_level2;
+#endif
             printf("Sending Value for well1 %.2f\n\r", oil_level);
+#if defined(TARGET_LPC1768)
             printf("Sending Value for well2 %.2f\n\r", oil_level2);
+#endif
             sock.connect("toolbox-connect.axeda.com", 80);
  
             snprintf(http_cmd, http_cmd_sz,  "POST /ammp/data/1/%s!%s HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: 65\r\n\r\n{\"data\":[{\"di\":{\"oil_level\":%.2f, \"oil_level2\":%.2f}}]}\r\n\r\n", MODEL, SERIAL_NUM, oil_level, oil_level2);
@@ -86,7 +124,7 @@
                 buffer[returnCode] = '\0';
                 printf("Received %d chars from server:\n\r%s\n", returnCode, buffer);
             }
-            led4 = returnCode;
+            //led4 = returnCode;
             sock.close();
         }