Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "NTPClient.h" 00004 #include "TextLCD.h" 00005 #include "Websocket.h" 00006 #include "Counter.h" 00007 #include "SDFileSystem.h" 00008 #include "uplink.h" 00009 00010 TextLCD lcd(p20, p19, p18, p17, p16, p15,TextLCD::LCD20x4); // rs, e, d4-d7 00011 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board 00012 00013 NTPClient ntp; 00014 int offset_DK = 7200; 00015 Counter T1(p22); 00016 AnalogIn tempsensor(p16); 00017 00018 00019 float ReadTempetur(void) 00020 { 00021 float tempreading=(tempsensor.read()*3.3-0.25)/0.028; 00022 return tempreading; 00023 } 00024 00025 float TankContens() 00026 { 00027 //beregner hvor meget der er tilbage 00028 return 1000-T1.Flow(); 00029 } 00030 00031 void InitLog(void) { 00032 FILE *fp; //Logfile 00033 fp = fopen("/sd/taptraq/Tank.log", "r"); 00034 if (fp == NULL) //For at være sikker på at der er en fil og skrive i 00035 fp = fopen("/sd/taptraq/Tank.log", "w"); 00036 fclose(fp); 00037 } 00038 00039 void LogToSd(void) 00040 { 00041 FILE *fp; //Logfile 00042 time_t seconds = time(NULL); 00043 char timestr[32]; 00044 seconds = time(NULL); 00045 strftime(timestr, 32, "%Y/%m/%d-%H:%M:%S", localtime(&seconds)); 00046 fp = fopen("/sd/taptraq/Tank.log", "a"); 00047 fprintf(fp,"%s,%.4f,%.1f\r\n", 00048 timestr,T1.Flow(),ReadTempetur()); 00049 fclose(fp); 00050 } 00051 00052 int main() 00053 { 00054 time_t seconds = time(NULL); 00055 char timestr[32]; 00056 lcd.printf("Establishing...\n"); 00057 lcd.printf("Network Connection\n"); 00058 EthernetInterface eth; 00059 eth.init(); //Use DHCP 00060 if (eth.connect()<0) NVIC_SystemReset(); 00061 lcd.cls(); 00062 lcd.printf("Located IP ADR....\n"); 00063 lcd.printf("IP: - %s\n", eth.getIPAddress()); 00064 printf("IP: %s\n", eth.getIPAddress()); 00065 Websocket ws("ws://sockets.mbed.org/ws/gert_lauritsen/rw"); 00066 wait(3); 00067 lcd.cls(); 00068 lcd.printf("Reconnecting...\n"); 00069 lcd.printf("TapTraQ Uplink\n"); 00070 while (!ws.connect()); 00071 lcd.cls(); 00072 lcd.printf("Faild Connect...\n"); 00073 lcd.printf("TapTraQ Uplink\n"); 00074 wait(5); 00075 TapTraqUplink Uplink(&ws); 00076 /* Set up NTP */ 00077 // printf("Setting up NTP \n\r"); 00078 //ntp.setTime("0.dk.pool.ntp.org",123); 00079 //ntp.setTime("ntp1.jst.mfeed.ad.jp",123); 00080 lcd.cls(); 00081 strftime(timestr, 32, "%H:%M", localtime(&seconds)); 00082 lcd.printf("%s \n",timestr); 00083 wait(1); 00084 InitLog(); 00085 while (1) { //Vis temperatur og mængde i tank 00086 lcd.cls(); 00087 seconds = time(NULL)+offset_DK; 00088 strftime(timestr, 32, "%H:%M", localtime(&seconds)); 00089 lcd.printf("TapTraQ Count System"); 00090 lcd.printf("KOLKKEN - %s\n",timestr); 00091 lcd.printf("TEMP %.2f C\n",ReadTempetur()); 00092 lcd.printf("TANK %.1f - %.1f L \n",TankContens(),T1.Flow()); 00093 Uplink.FlowFrame("1000",1,T1.Count,0,0,0,0,0,0); 00094 LogToSd(); 00095 wait(10); 00096 } 00097 }
Generated on Tue Jul 12 2022 14:07:51 by
1.7.2