V4

Dependencies:   BMP280

Fork of Thread_Communication_V3 by BDG

Committer:
dnonoo
Date:
Sat Dec 30 15:12:09 2017 +0000
Revision:
9:b838c5787ed7
Parent:
8:ab6322afa341
Child:
10:c10d1337d754
Network, SD card, Serial, LCD and sensors all work! :); ; ** Don't Press the User Button without an SD Card inserted!! **

Who changed what in which revision?

UserRevisionLine numberNew 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 7:f017a37bcf1b 10 #define SAMPLING_PERIOD 10
dnonoo 7:f017a37bcf1b 11 #define ON 1
dnonoo 7:f017a37bcf1b 12 #define OFF 0
dnonoo 7:f017a37bcf1b 13
dnonoo 9:b838c5787ed7 14 #if !FEATURE_LWIP
dnonoo 9:b838c5787ed7 15 #error [NOT_SUPPORTED] LWIP not supported for this target
dnonoo 9:b838c5787ed7 16 #endif
dnonoo 9:b838c5787ed7 17
dnonoo 9:b838c5787ed7 18 #include "mbed.h"
dnonoo 9:b838c5787ed7 19 #include "EthernetInterface.h"
dnonoo 9:b838c5787ed7 20 #include "TCPServer.h"
dnonoo 9:b838c5787ed7 21 #include "TCPSocket.h"
dnonoo 9:b838c5787ed7 22 #include <iostream>
dnonoo 9:b838c5787ed7 23 #include <string>
dnonoo 9:b838c5787ed7 24
dnonoo 9:b838c5787ed7 25 #define HTTP_STATUS_LINE "HTTP/1.0 200 OK"
dnonoo 9:b838c5787ed7 26 #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8"
dnonoo 9:b838c5787ed7 27 #define HTTP_MESSAGE_BODY1 "" \
dnonoo 9:b838c5787ed7 28 "<html>" "\r\n" \
dnonoo 9:b838c5787ed7 29 " <body style=\"display:flex;text-align:center\">" "\r\n" \
dnonoo 9:b838c5787ed7 30 " <meta http-equiv=\"refresh\" content=\"1; \"\> " "\r\n" \
dnonoo 9:b838c5787ed7 31 " <div style=\"margin:auto\">" "\r\n" \
dnonoo 9:b838c5787ed7 32 " <h1>Sensor Data</h1>" "\r\n" \
dnonoo 9:b838c5787ed7 33 " <p> LDR: " \
dnonoo 9:b838c5787ed7 34
dnonoo 9:b838c5787ed7 35 #define HTTP_MESSAGE_BODY2 "" \
dnonoo 9:b838c5787ed7 36 "</p>" "\r\n" \
dnonoo 9:b838c5787ed7 37 " </div>" "\r\n" \
dnonoo 9:b838c5787ed7 38 " </body>" "\r\n" \
dnonoo 9:b838c5787ed7 39 "</html>"
dnonoo 9:b838c5787ed7 40
dnonoo 9:b838c5787ed7 41 #define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n" \
dnonoo 9:b838c5787ed7 42 HTTP_HEADER_FIELDS "\r\n" \
dnonoo 9:b838c5787ed7 43 "\r\n" \
dnonoo 9:b838c5787ed7 44 HTTP_MESSAGE_BODY "\r\n"
dnonoo 9:b838c5787ed7 45
dnonoo 9:b838c5787ed7 46 #define IP "10.0.0.10"
dnonoo 9:b838c5787ed7 47 #define NETMASK "255.0.0.0"
dnonoo 9:b838c5787ed7 48 #define GATEWAY "10.0.0.1"
dnonoo 9:b838c5787ed7 49
dnonoo 9:b838c5787ed7 50
benparkes 0:cb3a5c15b01e 51 extern LCD lcd;
benparkes 0:cb3a5c15b01e 52 extern BMP280 sensor;
dnonoo 8:ab6322afa341 53 extern SDBlockDevice sd (PB_5, D12, D13, D10);
benparkes 0:cb3a5c15b01e 54
benparkes 0:cb3a5c15b01e 55 /* External LEDs as Open Drain */
dnonoo 7:f017a37bcf1b 56 extern DigitalOut Red_ext (PE_15);
dnonoo 7:f017a37bcf1b 57 extern DigitalOut Yellow_ext (PB_10);
dnonoo 7:f017a37bcf1b 58 extern DigitalOut Green_ext (PB_11);
benparkes 0:cb3a5c15b01e 59
benparkes 0:cb3a5c15b01e 60 /* Configure On-board LEDS */
dnonoo 7:f017a37bcf1b 61 extern DigitalOut Green_int (LED1);
dnonoo 7:f017a37bcf1b 62 extern DigitalOut Blue_int (LED2);
dnonoo 7:f017a37bcf1b 63 extern DigitalOut Red_int (LED3);
benparkes 0:cb3a5c15b01e 64
benparkes 0:cb3a5c15b01e 65 /* Configure Digital In Switches */
dnonoo 7:f017a37bcf1b 66 extern DigitalIn SW_L (PE_12);
dnonoo 7:f017a37bcf1b 67 extern DigitalIn SW_R (PE_14);
dnonoo 8:ab6322afa341 68 //extern DigitalIn SW_B (USER_BUTTON); //defined as interrupt now for SD
benparkes 0:cb3a5c15b01e 69 /* Configure Analogue Pins */
benparkes 0:cb3a5c15b01e 70 /* Analogue IN */
dnonoo 7:f017a37bcf1b 71 extern AnalogIn LDR_In (PA_0);
benparkes 0:cb3a5c15b01e 72
benparkes 0:cb3a5c15b01e 73 /* Congfigure Serial interface */
dnonoo 7:f017a37bcf1b 74 Serial pc(USBTX, USBRX);
dnonoo 7:f017a37bcf1b 75
dnonoo 7:f017a37bcf1b 76 /* Mail */
dnonoo 7:f017a37bcf1b 77 typedef struct {
dnonoo 7:f017a37bcf1b 78 float LDR_Value;
dnonoo 7:f017a37bcf1b 79 float temp_Value;
dnonoo 7:f017a37bcf1b 80 float press_Value;
dnonoo 7:f017a37bcf1b 81 } mail_t;
dnonoo 7:f017a37bcf1b 82
dnonoo 7:f017a37bcf1b 83 Mail<mail_t, 16> mail_box;
dnonoo 7:f017a37bcf1b 84
dnonoo 7:f017a37bcf1b 85 //data FIFO buffer
dnonoo 7:f017a37bcf1b 86 char data_buffer[MAX_SAMPLES][64];
dnonoo 7:f017a37bcf1b 87 int sample_h = 0;
dnonoo 7:f017a37bcf1b 88 int sample_t = 0;
dnonoo 7:f017a37bcf1b 89 int data_h = 0;
dnonoo 7:f017a37bcf1b 90 int data_t = 0;
dnonoo 7:f017a37bcf1b 91 struct tm * sample_epoch;
dnonoo 7:f017a37bcf1b 92
dnonoo 7:f017a37bcf1b 93
dnonoo 7:f017a37bcf1b 94 //Serial_CMD
dnonoo 7:f017a37bcf1b 95 volatile int rx_in=0;
dnonoo 7:f017a37bcf1b 96 char rx_buffer[32];
dnonoo 7:f017a37bcf1b 97 time_t raw_time = time(NULL);
dnonoo 7:f017a37bcf1b 98 char serial_buffer[80];
dnonoo 7:f017a37bcf1b 99
dnonoo 7:f017a37bcf1b 100 extern void POST();