KEIS
Dependencies: C12832_lcd EthernetInterface LM75B mbed-rtos mbed
main.cpp@0:18b7bb5ff184, 2013-09-28 (annotated)
- Committer:
- khayakawa
- Date:
- Sat Sep 28 08:52:28 2013 +0000
- Revision:
- 0:18b7bb5ff184
KEIS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
khayakawa | 0:18b7bb5ff184 | 1 | #include "mbed.h" |
khayakawa | 0:18b7bb5ff184 | 2 | #include "rtos.h" |
khayakawa | 0:18b7bb5ff184 | 3 | #include "EthernetInterface.h" |
khayakawa | 0:18b7bb5ff184 | 4 | #include "C12832_lcd.h" |
khayakawa | 0:18b7bb5ff184 | 5 | #include "LM75B.h" |
khayakawa | 0:18b7bb5ff184 | 6 | |
khayakawa | 0:18b7bb5ff184 | 7 | C12832_LCD lcd; |
khayakawa | 0:18b7bb5ff184 | 8 | |
khayakawa | 0:18b7bb5ff184 | 9 | const char* SERVER_ADDRESS = "192.168.50.121"; |
khayakawa | 0:18b7bb5ff184 | 10 | const int SERVER_PORT = 80; |
khayakawa | 0:18b7bb5ff184 | 11 | |
khayakawa | 0:18b7bb5ff184 | 12 | const char* MY_ADDRESS = "192.168.196.94"; |
khayakawa | 0:18b7bb5ff184 | 13 | const char* MY_MASK = "255.255.255.0"; |
khayakawa | 0:18b7bb5ff184 | 14 | const char* MY_GATEWAY = "192.168.196.254"; |
khayakawa | 0:18b7bb5ff184 | 15 | |
khayakawa | 0:18b7bb5ff184 | 16 | EthernetInterface eth; |
khayakawa | 0:18b7bb5ff184 | 17 | |
khayakawa | 0:18b7bb5ff184 | 18 | DigitalOut myled(LED1); |
khayakawa | 0:18b7bb5ff184 | 19 | LM75B tmp(p28,p27); |
khayakawa | 0:18b7bb5ff184 | 20 | |
khayakawa | 0:18b7bb5ff184 | 21 | float a[0] ; |
khayakawa | 0:18b7bb5ff184 | 22 | |
khayakawa | 0:18b7bb5ff184 | 23 | int main(void) { |
khayakawa | 0:18b7bb5ff184 | 24 | // set IPAddress , Mask , Gateway |
khayakawa | 0:18b7bb5ff184 | 25 | eth.init(MY_ADDRESS,MY_MASK,MY_GATEWAY); |
khayakawa | 0:18b7bb5ff184 | 26 | eth.connect(); |
khayakawa | 0:18b7bb5ff184 | 27 | printf("IP Address is %s\n", eth.getIPAddress()); |
khayakawa | 0:18b7bb5ff184 | 28 | |
khayakawa | 0:18b7bb5ff184 | 29 | TCPSocketConnection socket; |
khayakawa | 0:18b7bb5ff184 | 30 | |
khayakawa | 0:18b7bb5ff184 | 31 | int n; |
khayakawa | 0:18b7bb5ff184 | 32 | |
khayakawa | 0:18b7bb5ff184 | 33 | while (1) |
khayakawa | 0:18b7bb5ff184 | 34 | { |
khayakawa | 0:18b7bb5ff184 | 35 | a[0]=tmp.read(); |
khayakawa | 0:18b7bb5ff184 | 36 | if (socket.connect(SERVER_ADDRESS, SERVER_PORT) < 0) { |
khayakawa | 0:18b7bb5ff184 | 37 | printf("Unable to connect to (%s) on port (%d)\n", SERVER_ADDRESS, SERVER_PORT); |
khayakawa | 0:18b7bb5ff184 | 38 | }else { |
khayakawa | 0:18b7bb5ff184 | 39 | printf("connection succeded"); |
khayakawa | 0:18b7bb5ff184 | 40 | char buffer[900]; |
khayakawa | 0:18b7bb5ff184 | 41 | sprintf(buffer,"POST /next7/REST/Record/HayaLab03 HTTP/1.1\r\n" |
khayakawa | 0:18b7bb5ff184 | 42 | "Host: 192.168.50.121\r\n" |
khayakawa | 0:18b7bb5ff184 | 43 | "Content-Type: application/xml\r\n" |
khayakawa | 0:18b7bb5ff184 | 44 | "Content-Length: 690\r\n" |
khayakawa | 0:18b7bb5ff184 | 45 | "\r\n" |
khayakawa | 0:18b7bb5ff184 | 46 | "<PostData xmlns:a=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" |
khayakawa | 0:18b7bb5ff184 | 47 | "<PassCode>A123</PassCode>\r\n" |
khayakawa | 0:18b7bb5ff184 | 48 | "<StrDataKey />\r\n" |
khayakawa | 0:18b7bb5ff184 | 49 | "<StrDataValue />\r\n" |
khayakawa | 0:18b7bb5ff184 | 50 | "<NumDataKey>\r\n" |
khayakawa | 0:18b7bb5ff184 | 51 | "<a:string>Temp1</a:string>\r\n" |
khayakawa | 0:18b7bb5ff184 | 52 | "</NumDataKey>\r\n" |
khayakawa | 0:18b7bb5ff184 | 53 | "<NumDataValue>\r\n" |
khayakawa | 0:18b7bb5ff184 | 54 | "<a:decimal>%.2f</a:decimal>\r\n" |
khayakawa | 0:18b7bb5ff184 | 55 | "</NumDataValue>\r\n" |
khayakawa | 0:18b7bb5ff184 | 56 | "<DatetimeDataKey />\r\n" |
khayakawa | 0:18b7bb5ff184 | 57 | "<DatetimeDataValue />\r\n" |
khayakawa | 0:18b7bb5ff184 | 58 | "<ExNumDataKey />\r\n" |
khayakawa | 0:18b7bb5ff184 | 59 | "<ExNumDataValue />\r\n" |
khayakawa | 0:18b7bb5ff184 | 60 | "</PostData>\r\n" |
khayakawa | 0:18b7bb5ff184 | 61 | ,a[0]); |
khayakawa | 0:18b7bb5ff184 | 62 | // Send xml to Server |
khayakawa | 0:18b7bb5ff184 | 63 | socket.send_all(buffer,sizeof(buffer) - 1); |
khayakawa | 0:18b7bb5ff184 | 64 | |
khayakawa | 0:18b7bb5ff184 | 65 | // receive reply |
khayakawa | 0:18b7bb5ff184 | 66 | n=0; |
khayakawa | 0:18b7bb5ff184 | 67 | char buf[400]; |
khayakawa | 0:18b7bb5ff184 | 68 | n = socket.receive(buf, 400); |
khayakawa | 0:18b7bb5ff184 | 69 | buf[n] = '\0'; |
khayakawa | 0:18b7bb5ff184 | 70 | printf("%d %s",n, buf); |
khayakawa | 0:18b7bb5ff184 | 71 | lcd.cls(); |
khayakawa | 0:18b7bb5ff184 | 72 | lcd.locate(0,3); |
khayakawa | 0:18b7bb5ff184 | 73 | lcd.printf("temperature=%.2f\n",a[0]); |
khayakawa | 0:18b7bb5ff184 | 74 | } |
khayakawa | 0:18b7bb5ff184 | 75 | socket.close(); |
khayakawa | 0:18b7bb5ff184 | 76 | Thread::wait(60000); |
khayakawa | 0:18b7bb5ff184 | 77 | } |
khayakawa | 0:18b7bb5ff184 | 78 | |
khayakawa | 0:18b7bb5ff184 | 79 | } |