HTTP_SERVER

Dependencies:   mbed mbed-rtos SDFileSystem EthernetInterface BME280

Committer:
barti19941
Date:
Tue Nov 13 11:46:10 2018 +0000
Revision:
1:baaf95f8d272
Parent:
0:795a02b2bb68
Child:
2:33833f64246f
Wersja 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
barti19941 0:795a02b2bb68 1 #include "mbed.h"
barti19941 0:795a02b2bb68 2 #include "SDFileSystem.h"
barti19941 1:baaf95f8d272 3 #include "EthernetInterface.h"
barti19941 1:baaf95f8d272 4 #include <iostream>
barti19941 1:baaf95f8d272 5 #include <fstream>
barti19941 0:795a02b2bb68 6
barti19941 1:baaf95f8d272 7 #define NUMBER_OF_LINES 23
barti19941 1:baaf95f8d272 8 #define COLOR_LINE 12
barti19941 1:baaf95f8d272 9 #define TEMPERATURE_LINE 17
barti19941 1:baaf95f8d272 10 #define PRESSURE_LINE 18
barti19941 1:baaf95f8d272 11 #define HUMADITY_LINE 19
barti19941 1:baaf95f8d272 12 #define RAINFALL_LINE 20
barti19941 1:baaf95f8d272 13 #define TIME_LINE 21
barti19941 1:baaf95f8d272 14
barti19941 1:baaf95f8d272 15 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
barti19941 0:795a02b2bb68 16 Serial pc(USBTX, USBRX);
barti19941 1:baaf95f8d272 17 string file_content[NUMBER_OF_LINES];
barti19941 0:795a02b2bb68 18
barti19941 1:baaf95f8d272 19 void initializeEthernet(void)
barti19941 1:baaf95f8d272 20 {
barti19941 1:baaf95f8d272 21 EthernetInterface eth;
barti19941 1:baaf95f8d272 22 const char *ip = "192.168.1.2";
barti19941 1:baaf95f8d272 23 const char *mask = "255.255.255.0";
barti19941 1:baaf95f8d272 24 const char *gateway = "192.168.1.1";
barti19941 1:baaf95f8d272 25 if(!eth.init(ip,mask,gateway))
barti19941 1:baaf95f8d272 26 {
barti19941 1:baaf95f8d272 27 pc.printf("Ethernet card initialized successfully.\r");
barti19941 1:baaf95f8d272 28 eth.connect();
barti19941 1:baaf95f8d272 29 pc.printf("IP address: %s\n",eth.getIPAddress());
barti19941 1:baaf95f8d272 30 pc.printf("Network mask: %s\n",eth.getNetworkMask());
barti19941 1:baaf95f8d272 31 pc.printf("Gateway: %s\n",eth.getGateway());
barti19941 1:baaf95f8d272 32 pc.printf("MAC address: %s\n",eth.getMACAddress());
barti19941 0:795a02b2bb68 33 }
barti19941 1:baaf95f8d272 34 else
barti19941 1:baaf95f8d272 35 pc.printf("Ethernet card could not be initialized.\r");
barti19941 1:baaf95f8d272 36 return;
barti19941 1:baaf95f8d272 37 }
barti19941 0:795a02b2bb68 38
barti19941 1:baaf95f8d272 39 void readHTMLCode(void)
barti19941 1:baaf95f8d272 40 {
barti19941 1:baaf95f8d272 41 fstream file;
barti19941 1:baaf95f8d272 42 int cnt = 0;
barti19941 1:baaf95f8d272 43 for (int i = 0; i < NUMBER_OF_LINES; i++)
barti19941 1:baaf95f8d272 44 file_content[i] = " ";
barti19941 1:baaf95f8d272 45 file.open("/sd/index.html", ios::in);
barti19941 1:baaf95f8d272 46 if (file.good())
barti19941 1:baaf95f8d272 47 {
barti19941 1:baaf95f8d272 48 pc.printf("The index.html file has been opened. \r");
barti19941 1:baaf95f8d272 49 while(!file.eof())
barti19941 1:baaf95f8d272 50 {
barti19941 1:baaf95f8d272 51 getline(file,file_content[cnt]);
barti19941 1:baaf95f8d272 52 cnt++;
barti19941 1:baaf95f8d272 53 }
barti19941 1:baaf95f8d272 54 file.close();
barti19941 1:baaf95f8d272 55 pc.printf("The file has been closed. \r");
barti19941 0:795a02b2bb68 56 }
barti19941 1:baaf95f8d272 57 else
barti19941 1:baaf95f8d272 58 {
barti19941 1:baaf95f8d272 59 pc.printf("The file could not be opened. \r");
barti19941 1:baaf95f8d272 60 return;
barti19941 1:baaf95f8d272 61 }
barti19941 1:baaf95f8d272 62 }
barti19941 0:795a02b2bb68 63
barti19941 1:baaf95f8d272 64 void initializeSerialPC(void)
barti19941 1:baaf95f8d272 65 {
barti19941 1:baaf95f8d272 66 pc.baud(115200);
barti19941 1:baaf95f8d272 67 pc.printf("Serial port initialized. \r");
barti19941 0:795a02b2bb68 68 }
barti19941 1:baaf95f8d272 69
barti19941 1:baaf95f8d272 70 int main()
barti19941 1:baaf95f8d272 71 {
barti19941 1:baaf95f8d272 72 initializeSerialPC();
barti19941 1:baaf95f8d272 73 readHTMLCode();
barti19941 1:baaf95f8d272 74 initializeEthernet();
barti19941 1:baaf95f8d272 75 while(1);
barti19941 1:baaf95f8d272 76 }