Network, SD card, Serial, LCD and sensors all work! :) ** Don't Press the User Button without an SD Card inserted!! **
Dependencies: BMP280
Fork of Thread_Communication_V2 by
main.h@15:864d936b51cf, 2018-01-06 (annotated)
- Committer:
- dnonoo
- Date:
- Sat Jan 06 13:52:46 2018 +0000
- Revision:
- 15:864d936b51cf
- Parent:
- 14:7c4d87dfc388
new okokokok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benparkes | 0:cb3a5c15b01e | 1 | #include "LCD.h" |
benparkes | 0:cb3a5c15b01e | 2 | #include "BMP280.h" |
dnonoo | 8:ab6322afa341 | 3 | #include "SDBlockDevice.h" |
dnonoo | 8:ab6322afa341 | 4 | #include "FATFileSystem.h" |
benparkes | 0:cb3a5c15b01e | 5 | |
dnonoo | 7:f017a37bcf1b | 6 | #define ENTER_KEY 1 |
dnonoo | 7:f017a37bcf1b | 7 | #define MAX_SAMPLES 120 |
dnonoo | 7:f017a37bcf1b | 8 | #define SENSOR_UPDATE 1 |
dnonoo | 7:f017a37bcf1b | 9 | #define DATA_READY 1 |
dnonoo | 14:7c4d87dfc388 | 10 | #define LCD_REFRESH 1 // define time for LCD to refresh (ever 1 second for clock) |
dnonoo | 14:7c4d87dfc388 | 11 | #define LCD_READY 1 // LCD ISR to LCD thread Signal |
dnonoo | 7:f017a37bcf1b | 12 | #define ON 1 |
dnonoo | 7:f017a37bcf1b | 13 | #define OFF 0 |
dnonoo | 7:f017a37bcf1b | 14 | |
dnonoo | 9:b838c5787ed7 | 15 | #if !FEATURE_LWIP |
dnonoo | 9:b838c5787ed7 | 16 | #error [NOT_SUPPORTED] LWIP not supported for this target |
dnonoo | 9:b838c5787ed7 | 17 | #endif |
dnonoo | 9:b838c5787ed7 | 18 | |
dnonoo | 9:b838c5787ed7 | 19 | #include "mbed.h" |
dnonoo | 9:b838c5787ed7 | 20 | #include "EthernetInterface.h" |
dnonoo | 9:b838c5787ed7 | 21 | #include "TCPServer.h" |
dnonoo | 9:b838c5787ed7 | 22 | #include "TCPSocket.h" |
dnonoo | 9:b838c5787ed7 | 23 | #include <iostream> |
dnonoo | 9:b838c5787ed7 | 24 | #include <string> |
dnonoo | 9:b838c5787ed7 | 25 | |
dnonoo | 9:b838c5787ed7 | 26 | #define HTTP_STATUS_LINE "HTTP/1.0 200 OK" |
dnonoo | 9:b838c5787ed7 | 27 | #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8" |
dnonoo | 9:b838c5787ed7 | 28 | #define HTTP_MESSAGE_BODY1 "" \ |
dnonoo | 9:b838c5787ed7 | 29 | "<html>" "\r\n" \ |
dnonoo | 9:b838c5787ed7 | 30 | " <body style=\"display:flex;text-align:center\">" "\r\n" \ |
dnonoo | 9:b838c5787ed7 | 31 | " <meta http-equiv=\"refresh\" content=\"1; \"\> " "\r\n" \ |
dnonoo | 9:b838c5787ed7 | 32 | " <div style=\"margin:auto\">" "\r\n" \ |
dnonoo | 9:b838c5787ed7 | 33 | " <h1>Sensor Data</h1>" "\r\n" \ |
dnonoo | 13:089f3adb3813 | 34 | " <p> Date/Time: " \ |
dnonoo | 9:b838c5787ed7 | 35 | |
dnonoo | 9:b838c5787ed7 | 36 | #define HTTP_MESSAGE_BODY2 "" \ |
dnonoo | 9:b838c5787ed7 | 37 | "</p>" "\r\n" \ |
dnonoo | 9:b838c5787ed7 | 38 | " </div>" "\r\n" \ |
dnonoo | 9:b838c5787ed7 | 39 | " </body>" "\r\n" \ |
dnonoo | 9:b838c5787ed7 | 40 | "</html>" |
dnonoo | 9:b838c5787ed7 | 41 | |
dnonoo | 9:b838c5787ed7 | 42 | #define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n" \ |
dnonoo | 9:b838c5787ed7 | 43 | HTTP_HEADER_FIELDS "\r\n" \ |
dnonoo | 9:b838c5787ed7 | 44 | "\r\n" \ |
dnonoo | 9:b838c5787ed7 | 45 | HTTP_MESSAGE_BODY "\r\n" |
dnonoo | 9:b838c5787ed7 | 46 | |
dnonoo | 9:b838c5787ed7 | 47 | #define IP "10.0.0.10" |
dnonoo | 9:b838c5787ed7 | 48 | #define NETMASK "255.0.0.0" |
dnonoo | 9:b838c5787ed7 | 49 | #define GATEWAY "10.0.0.1" |
dnonoo | 9:b838c5787ed7 | 50 | |
dnonoo | 9:b838c5787ed7 | 51 | |
benparkes | 0:cb3a5c15b01e | 52 | extern LCD lcd; |
benparkes | 0:cb3a5c15b01e | 53 | extern BMP280 sensor; |
dnonoo | 8:ab6322afa341 | 54 | extern SDBlockDevice sd (PB_5, D12, D13, D10); |
benparkes | 0:cb3a5c15b01e | 55 | |
benparkes | 0:cb3a5c15b01e | 56 | /* External LEDs as Open Drain */ |
dnonoo | 7:f017a37bcf1b | 57 | extern DigitalOut Red_ext (PE_15); |
dnonoo | 7:f017a37bcf1b | 58 | extern DigitalOut Yellow_ext (PB_10); |
dnonoo | 7:f017a37bcf1b | 59 | extern DigitalOut Green_ext (PB_11); |
benparkes | 0:cb3a5c15b01e | 60 | |
benparkes | 0:cb3a5c15b01e | 61 | /* Configure On-board LEDS */ |
dnonoo | 7:f017a37bcf1b | 62 | extern DigitalOut Green_int (LED1); |
dnonoo | 7:f017a37bcf1b | 63 | extern DigitalOut Blue_int (LED2); |
dnonoo | 7:f017a37bcf1b | 64 | extern DigitalOut Red_int (LED3); |
benparkes | 0:cb3a5c15b01e | 65 | |
benparkes | 0:cb3a5c15b01e | 66 | /* Configure Digital In Switches */ |
dnonoo | 7:f017a37bcf1b | 67 | extern DigitalIn SW_L (PE_12); |
dnonoo | 7:f017a37bcf1b | 68 | extern DigitalIn SW_R (PE_14); |
dnonoo | 10:c10d1337d754 | 69 | extern DigitalIn sdIn (PE_10); |
dnonoo | 8:ab6322afa341 | 70 | //extern DigitalIn SW_B (USER_BUTTON); //defined as interrupt now for SD |
benparkes | 0:cb3a5c15b01e | 71 | /* Configure Analogue Pins */ |
benparkes | 0:cb3a5c15b01e | 72 | /* Analogue IN */ |
dnonoo | 7:f017a37bcf1b | 73 | extern AnalogIn LDR_In (PA_0); |
benparkes | 0:cb3a5c15b01e | 74 | |
benparkes | 0:cb3a5c15b01e | 75 | /* Congfigure Serial interface */ |
dnonoo | 7:f017a37bcf1b | 76 | Serial pc(USBTX, USBRX); |
dnonoo | 7:f017a37bcf1b | 77 | |
dnonoo | 7:f017a37bcf1b | 78 | /* Mail */ |
dnonoo | 7:f017a37bcf1b | 79 | typedef struct { |
dnonoo | 7:f017a37bcf1b | 80 | float LDR_Value; |
dnonoo | 7:f017a37bcf1b | 81 | float temp_Value; |
dnonoo | 7:f017a37bcf1b | 82 | float press_Value; |
dnonoo | 7:f017a37bcf1b | 83 | } mail_t; |
dnonoo | 7:f017a37bcf1b | 84 | |
dnonoo | 7:f017a37bcf1b | 85 | Mail<mail_t, 16> mail_box; |
dnonoo | 11:19135c83c208 | 86 | //Mail<mail_t, 16> mail_box2; |
dnonoo | 7:f017a37bcf1b | 87 | |
dnonoo | 7:f017a37bcf1b | 88 | //data FIFO buffer |
dnonoo | 7:f017a37bcf1b | 89 | char data_buffer[MAX_SAMPLES][64]; |
dnonoo | 7:f017a37bcf1b | 90 | int sample_h = 0; |
dnonoo | 7:f017a37bcf1b | 91 | int sample_t = 0; |
dnonoo | 7:f017a37bcf1b | 92 | int data_h = 0; |
dnonoo | 7:f017a37bcf1b | 93 | int data_t = 0; |
dnonoo | 7:f017a37bcf1b | 94 | struct tm * sample_epoch; |
dnonoo | 7:f017a37bcf1b | 95 | |
dnonoo | 7:f017a37bcf1b | 96 | |
dnonoo | 7:f017a37bcf1b | 97 | //Serial_CMD |
dnonoo | 7:f017a37bcf1b | 98 | volatile int rx_in=0; |
dnonoo | 7:f017a37bcf1b | 99 | char rx_buffer[32]; |
dnonoo | 7:f017a37bcf1b | 100 | time_t raw_time = time(NULL); |
dnonoo | 7:f017a37bcf1b | 101 | char serial_buffer[80]; |
dnonoo | 7:f017a37bcf1b | 102 | |
dnonoo | 7:f017a37bcf1b | 103 | extern void POST(); |