ported Axeda app. to mbed LPC1114FN28 with WIZ550io

Dependencies:   W5500Interface mbed

Fork of AxedaGo-mbedNXP by Axeda Corp

Committer:
embeddist
Date:
Wed Mar 04 10:33:10 2015 +0000
Revision:
7:880cc185d511
Parent:
6:1f7647c5691a
ported Axeda app. to mbed LPC1114FN28 with WIZ550io

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AxedaCorp 0:ab4e84579da0 1 #include "mbed.h"
AxedaCorp 0:ab4e84579da0 2 #include "EthernetInterface.h"
embeddist 7:880cc185d511 3
embeddist 7:880cc185d511 4 #if defined(TARGET_LPC1114)
embeddist 7:880cc185d511 5 SPI spi(dp2, dp1, dp6); // mosi, miso, sclk
embeddist 7:880cc185d511 6 EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset
embeddist 7:880cc185d511 7 AnalogIn pot1(dp13);
embeddist 7:880cc185d511 8 #else
embeddist 7:880cc185d511 9 EthernetInterface eth;
embeddist 7:880cc185d511 10 AnalogIn pot1(p19);
embeddist 7:880cc185d511 11 AnalogIn pot2(p20);
embeddist 7:880cc185d511 12 #endif
embeddist 7:880cc185d511 13
embeddist 7:880cc185d511 14 #if defined(TARGET_LPC1768)
AxedaCorp 0:ab4e84579da0 15 DigitalOut led1(LED1);
AxedaCorp 0:ab4e84579da0 16 DigitalOut led2(LED2);
AxedaCorp 0:ab4e84579da0 17 DigitalOut led3(LED3);
embeddist 7:880cc185d511 18 DigitalOut led4(LED4);
embeddist 7:880cc185d511 19 #endif
embeddist 7:880cc185d511 20
embeddist 7:880cc185d511 21 TCPSocketConnection sock;
AxedaCorp 0:ab4e84579da0 22
AxedaCorp 0:ab4e84579da0 23 int main()
AxedaCorp 0:ab4e84579da0 24 {
AxedaCorp 0:ab4e84579da0 25 char *MODEL = "mbed";
embeddist 7:880cc185d511 26 char *SERIAL_NUM = "nlr__embeddist_gmail_com___343881";
AxedaCorp 0:ab4e84579da0 27 float DEADBAND = 0.015;
AxedaCorp 0:ab4e84579da0 28
AxedaCorp 0:ab4e84579da0 29 char* ip;
AxedaCorp 0:ab4e84579da0 30
AxedaCorp 3:359e019da3b9 31 int http_cmd_sz=800;
AxedaCorp 3:359e019da3b9 32 char http_cmd[http_cmd_sz];
AxedaCorp 3:359e019da3b9 33 int buffer_sz=300;
AxedaCorp 3:359e019da3b9 34 char buffer[buffer_sz];
AxedaCorp 0:ab4e84579da0 35 int returnCode = 0;
AxedaCorp 0:ab4e84579da0 36
embeddist 7:880cc185d511 37 #if defined(TARGET_LPC1768)
AxedaCorp 0:ab4e84579da0 38 led1 = 1;
AxedaCorp 0:ab4e84579da0 39 led2 = 1;
AxedaCorp 0:ab4e84579da0 40 led3 = 1;
AxedaCorp 0:ab4e84579da0 41 led4 = 1;
embeddist 7:880cc185d511 42 #endif
AxedaCorp 0:ab4e84579da0 43
AxedaCorp 0:ab4e84579da0 44 printf("initializing Ethernet\r\n");
AxedaCorp 0:ab4e84579da0 45 returnCode = eth.init(); //Use DHCP
AxedaCorp 0:ab4e84579da0 46
AxedaCorp 0:ab4e84579da0 47 if ( returnCode == 0 )
AxedaCorp 0:ab4e84579da0 48 {
AxedaCorp 0:ab4e84579da0 49 printf(" - Ethernet ready\r\n");
embeddist 7:880cc185d511 50 #if defined(TARGET_LPC1768)
AxedaCorp 0:ab4e84579da0 51 led1 = returnCode;
embeddist 7:880cc185d511 52 #endif
AxedaCorp 0:ab4e84579da0 53 }
AxedaCorp 0:ab4e84579da0 54 else
AxedaCorp 0:ab4e84579da0 55 {
AxedaCorp 0:ab4e84579da0 56 printf(" - Could not initialize Ethernet - ending\r\n");
AxedaCorp 0:ab4e84579da0 57 return 0;
AxedaCorp 0:ab4e84579da0 58 }
AxedaCorp 0:ab4e84579da0 59
AxedaCorp 0:ab4e84579da0 60 printf("Ethernet.connecting \r\n");
AxedaCorp 0:ab4e84579da0 61 returnCode = eth.connect();
AxedaCorp 0:ab4e84579da0 62 printf(" - connecting returned %d \r\n", returnCode);
embeddist 7:880cc185d511 63 #if defined(TARGET_LPC1768)
AxedaCorp 0:ab4e84579da0 64 led2 = returnCode != -1 ? 0: 1;
embeddist 7:880cc185d511 65 #endif
AxedaCorp 0:ab4e84579da0 66 printf("Trying to get IP address..\r\n");
AxedaCorp 0:ab4e84579da0 67 ip = eth.getIPAddress();
embeddist 7:880cc185d511 68 #if defined(TARGET_LPC1768)
AxedaCorp 0:ab4e84579da0 69 led3 = strlen(ip)<4 ? 1: 0;
embeddist 7:880cc185d511 70 #endif
AxedaCorp 0:ab4e84579da0 71 printf(" - IP address:%s\r\n", ip);
AxedaCorp 0:ab4e84579da0 72
AxedaCorp 3:359e019da3b9 73 float oil_level = 0.0;
AxedaCorp 4:22d6467147a5 74 float oil_level2= 0.0;
AxedaCorp 0:ab4e84579da0 75 float oldPotVal = -2.0;
AxedaCorp 4:22d6467147a5 76 float oldPotVal2 = -2.0;
AxedaCorp 0:ab4e84579da0 77
AxedaCorp 0:ab4e84579da0 78 while(1) {
AxedaCorp 0:ab4e84579da0 79
AxedaCorp 3:359e019da3b9 80 oil_level = pot1.read();
embeddist 7:880cc185d511 81 #if defined(TARGET_LPC1768)
AxedaCorp 4:22d6467147a5 82 oil_level2=pot2.read();
embeddist 7:880cc185d511 83 #endif
embeddist 7:880cc185d511 84 //if ( abs(oil_level - oldPotVal) < DEADBAND && abs(oil_level2 - oldPotVal2) < DEADBAND) //LPC1768
embeddist 7:880cc185d511 85 if ( abs(oil_level - oldPotVal) < DEADBAND) //LPC1114
AxedaCorp 0:ab4e84579da0 86 {
AxedaCorp 0:ab4e84579da0 87 continue;
AxedaCorp 0:ab4e84579da0 88 }
AxedaCorp 0:ab4e84579da0 89 else
AxedaCorp 0:ab4e84579da0 90 {
embeddist 7:880cc185d511 91 //led4 = 1;
AxedaCorp 3:359e019da3b9 92 oldPotVal = oil_level;
embeddist 7:880cc185d511 93 #if defined(TARGET_LPC1768)
embeddist 7:880cc185d511 94 oldPotVal2 = oil_level2;
embeddist 7:880cc185d511 95 #endif
AxedaCorp 4:22d6467147a5 96 printf("Sending Value for well1 %.2f\n\r", oil_level);
embeddist 7:880cc185d511 97 #if defined(TARGET_LPC1768)
AxedaCorp 4:22d6467147a5 98 printf("Sending Value for well2 %.2f\n\r", oil_level2);
embeddist 7:880cc185d511 99 #endif
AxedaCorp 6:1f7647c5691a 100 sock.connect("toolbox-connect.axeda.com", 80);
AxedaCorp 0:ab4e84579da0 101
AxedaCorp 4:22d6467147a5 102 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);
AxedaCorp 5:1b8ad120cf29 103 sock.send_all(http_cmd, http_cmd_sz-1);
AxedaCorp 0:ab4e84579da0 104
AxedaCorp 5:1b8ad120cf29 105 while ( (returnCode = sock.receive(buffer, buffer_sz-1)) > 0)
AxedaCorp 0:ab4e84579da0 106 {
AxedaCorp 0:ab4e84579da0 107 buffer[returnCode] = '\0';
AxedaCorp 0:ab4e84579da0 108 printf("Received %d chars from server:\n\r%s\n", returnCode, buffer);
AxedaCorp 0:ab4e84579da0 109 }
embeddist 7:880cc185d511 110 //led4 = returnCode;
AxedaCorp 0:ab4e84579da0 111 sock.close();
AxedaCorp 0:ab4e84579da0 112 }
AxedaCorp 0:ab4e84579da0 113
AxedaCorp 0:ab4e84579da0 114 }
AxedaCorp 0:ab4e84579da0 115
AxedaCorp 0:ab4e84579da0 116 }