AxedaGo-mbed Demo - WIZwiki_W7500 or Platform+ W5500 (WIZnet) + Sensor (Photosell), This code tested on FRDM-KL25Z, LPCXpresso8324-MAX, NUCLEO_F103RB and WIZwiki_W7500

Dependencies:   AxedaGo-mbedNXP WIZnetInterface mbed

Fork of AxedaGo-mbed_WIZnetInterface by Soohwan Kim

Committer:
embeddist
Date:
Thu Jun 18 04:05:40 2015 +0000
Revision:
7:979a654458c7
Parent:
6:1f7647c5691a
Child:
8:4652dbf6461d
AxedaGo-mbed for WIZwiki_W7500 and W5500 Ethernet Shield

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"
AxedaCorp 0:ab4e84579da0 3
embeddist 7:979a654458c7 4 AnalogIn pot1(A0);
embeddist 7:979a654458c7 5 AnalogIn pot2(A1);
embeddist 7:979a654458c7 6
AxedaCorp 0:ab4e84579da0 7 DigitalOut led1(LED1);
AxedaCorp 0:ab4e84579da0 8 DigitalOut led2(LED2);
AxedaCorp 0:ab4e84579da0 9 DigitalOut led3(LED3);
AxedaCorp 0:ab4e84579da0 10 DigitalOut led4(LED4);
embeddist 7:979a654458c7 11
embeddist 7:979a654458c7 12 #ifdef TARGET_WIZwiki_W7500
embeddist 7:979a654458c7 13 EthernetInterface eth;
embeddist 7:979a654458c7 14 #else
embeddist 7:979a654458c7 15
embeddist 7:979a654458c7 16 #if defined(TARGET_NUCLEO_F103RB)
embeddist 7:979a654458c7 17 SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk
embeddist 7:979a654458c7 18 EthernetInterface eth(&spi, PB_6, PA_9); // spi, cs, reset
embeddist 7:979a654458c7 19 #else //tested on FRDM-KL25Z, LPCXpresso8324-MAX
embeddist 7:979a654458c7 20 SPI spi(D11, D12, D13); // mosi, miso, sclk
embeddist 7:979a654458c7 21 EthernetInterface eth(&spi, D10, D9); // spi, cs, reset
embeddist 7:979a654458c7 22 #endif
embeddist 7:979a654458c7 23
embeddist 7:979a654458c7 24 #endif //#if defined TARGET_WIZwiki_W7500
embeddist 7:979a654458c7 25
embeddist 7:979a654458c7 26 TCPSocketConnection sock;
embeddist 7:979a654458c7 27
AxedaCorp 0:ab4e84579da0 28 int main()
AxedaCorp 0:ab4e84579da0 29 {
embeddist 7:979a654458c7 30 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x1D, 0x62, 0x11};
AxedaCorp 0:ab4e84579da0 31 char *MODEL = "mbed";
embeddist 7:979a654458c7 32 char *SERIAL_NUM = "nlr__embeddist_gmail_com___343881";
embeddist 7:979a654458c7 33 float DEADBAND = 0.015;
AxedaCorp 0:ab4e84579da0 34 char* ip;
AxedaCorp 0:ab4e84579da0 35
AxedaCorp 3:359e019da3b9 36 int http_cmd_sz=800;
AxedaCorp 3:359e019da3b9 37 char http_cmd[http_cmd_sz];
AxedaCorp 3:359e019da3b9 38 int buffer_sz=300;
AxedaCorp 3:359e019da3b9 39 char buffer[buffer_sz];
AxedaCorp 0:ab4e84579da0 40 int returnCode = 0;
embeddist 7:979a654458c7 41
AxedaCorp 0:ab4e84579da0 42 led1 = 1;
AxedaCorp 0:ab4e84579da0 43 led2 = 1;
AxedaCorp 0:ab4e84579da0 44 led3 = 1;
AxedaCorp 0:ab4e84579da0 45 led4 = 1;
embeddist 7:979a654458c7 46
AxedaCorp 0:ab4e84579da0 47 printf("initializing Ethernet\r\n");
embeddist 7:979a654458c7 48 eth.init(mac_addr); //Use DHCP
AxedaCorp 0:ab4e84579da0 49 if ( returnCode == 0 )
AxedaCorp 0:ab4e84579da0 50 {
AxedaCorp 0:ab4e84579da0 51 printf(" - Ethernet ready\r\n");
AxedaCorp 0:ab4e84579da0 52 led1 = returnCode;
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();
embeddist 7:979a654458c7 62 eth.ethernet_link();
AxedaCorp 0:ab4e84579da0 63 printf(" - connecting returned %d \r\n", returnCode);
AxedaCorp 0:ab4e84579da0 64 led2 = returnCode != -1 ? 0: 1;
AxedaCorp 0:ab4e84579da0 65 printf("Trying to get IP address..\r\n");
AxedaCorp 0:ab4e84579da0 66 ip = eth.getIPAddress();
AxedaCorp 0:ab4e84579da0 67 led3 = strlen(ip)<4 ? 1: 0;
AxedaCorp 0:ab4e84579da0 68 printf(" - IP address:%s\r\n", ip);
AxedaCorp 0:ab4e84579da0 69
AxedaCorp 3:359e019da3b9 70 float oil_level = 0.0;
AxedaCorp 4:22d6467147a5 71 float oil_level2= 0.0;
AxedaCorp 0:ab4e84579da0 72 float oldPotVal = -2.0;
AxedaCorp 4:22d6467147a5 73 float oldPotVal2 = -2.0;
AxedaCorp 0:ab4e84579da0 74
AxedaCorp 0:ab4e84579da0 75 while(1) {
AxedaCorp 3:359e019da3b9 76 oil_level = pot1.read();
embeddist 7:979a654458c7 77 oil_level2= pot2.read();
AxedaCorp 0:ab4e84579da0 78
AxedaCorp 4:22d6467147a5 79 if ( abs(oil_level - oldPotVal) < DEADBAND && abs(oil_level2 - oldPotVal2) < DEADBAND)
AxedaCorp 0:ab4e84579da0 80 {
AxedaCorp 0:ab4e84579da0 81 continue;
AxedaCorp 0:ab4e84579da0 82 }
AxedaCorp 0:ab4e84579da0 83 else
AxedaCorp 0:ab4e84579da0 84 {
AxedaCorp 0:ab4e84579da0 85 led4 = 1;
AxedaCorp 3:359e019da3b9 86 oldPotVal = oil_level;
AxedaCorp 4:22d6467147a5 87 oldPotVal2 = oil_level2;
AxedaCorp 4:22d6467147a5 88 printf("Sending Value for well1 %.2f\n\r", oil_level);
AxedaCorp 4:22d6467147a5 89 printf("Sending Value for well2 %.2f\n\r", oil_level2);
AxedaCorp 6:1f7647c5691a 90 sock.connect("toolbox-connect.axeda.com", 80);
AxedaCorp 0:ab4e84579da0 91
AxedaCorp 4:22d6467147a5 92 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 93 sock.send_all(http_cmd, http_cmd_sz-1);
AxedaCorp 0:ab4e84579da0 94
AxedaCorp 5:1b8ad120cf29 95 while ( (returnCode = sock.receive(buffer, buffer_sz-1)) > 0)
AxedaCorp 0:ab4e84579da0 96 {
AxedaCorp 0:ab4e84579da0 97 buffer[returnCode] = '\0';
AxedaCorp 0:ab4e84579da0 98 printf("Received %d chars from server:\n\r%s\n", returnCode, buffer);
AxedaCorp 0:ab4e84579da0 99 }
AxedaCorp 0:ab4e84579da0 100 led4 = returnCode;
AxedaCorp 0:ab4e84579da0 101 sock.close();
AxedaCorp 0:ab4e84579da0 102 }
AxedaCorp 0:ab4e84579da0 103
AxedaCorp 0:ab4e84579da0 104 }
AxedaCorp 0:ab4e84579da0 105
AxedaCorp 0:ab4e84579da0 106 }