HTTP_SERVER
Dependencies: mbed mbed-rtos SDFileSystem EthernetInterface BME280
main.cpp
- Committer:
- barti19941
- Date:
- 2018-11-13
- Revision:
- 1:baaf95f8d272
- Parent:
- 0:795a02b2bb68
- Child:
- 2:33833f64246f
File content as of revision 1:baaf95f8d272:
#include "mbed.h" #include "SDFileSystem.h" #include "EthernetInterface.h" #include <iostream> #include <fstream> #define NUMBER_OF_LINES 23 #define COLOR_LINE 12 #define TEMPERATURE_LINE 17 #define PRESSURE_LINE 18 #define HUMADITY_LINE 19 #define RAINFALL_LINE 20 #define TIME_LINE 21 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); Serial pc(USBTX, USBRX); string file_content[NUMBER_OF_LINES]; void initializeEthernet(void) { EthernetInterface eth; const char *ip = "192.168.1.2"; const char *mask = "255.255.255.0"; const char *gateway = "192.168.1.1"; if(!eth.init(ip,mask,gateway)) { pc.printf("Ethernet card initialized successfully.\r"); eth.connect(); pc.printf("IP address: %s\n",eth.getIPAddress()); pc.printf("Network mask: %s\n",eth.getNetworkMask()); pc.printf("Gateway: %s\n",eth.getGateway()); pc.printf("MAC address: %s\n",eth.getMACAddress()); } else pc.printf("Ethernet card could not be initialized.\r"); return; } void readHTMLCode(void) { fstream file; int cnt = 0; for (int i = 0; i < NUMBER_OF_LINES; i++) file_content[i] = " "; file.open("/sd/index.html", ios::in); if (file.good()) { pc.printf("The index.html file has been opened. \r"); while(!file.eof()) { getline(file,file_content[cnt]); cnt++; } file.close(); pc.printf("The file has been closed. \r"); } else { pc.printf("The file could not be opened. \r"); return; } } void initializeSerialPC(void) { pc.baud(115200); pc.printf("Serial port initialized. \r"); } int main() { initializeSerialPC(); readHTMLCode(); initializeEthernet(); while(1); }