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 BDG

Committer:
dnonoo
Date:
Thu Jan 04 20:33:17 2018 +0000
Revision:
11:19135c83c208
Parent:
10:c10d1337d754
Child:
13:089f3adb3813
have a look i cant remember

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