Yasushi TAUCHI / Mbed 2 deprecated temp_WebServer

Dependencies:   MSCUsbHost NetServices RPCInterface TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
yueee_yt
Date:
Wed Aug 22 05:10:09 2012 +0000
Parent:
0:fd83f3540b1a
Commit message:
???????LM35??????WebServer

Changed in this revision

MSCUsbHost.lib Show annotated file Show diff for this revision Revisions of this file
RPCInterface.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MSCUsbHost.lib	Wed Aug 22 05:10:09 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/yueee_yt/code/MSCUsbHost/#889e21137f46
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RPCInterface.lib	Wed Aug 22 05:10:09 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MichaelW/code/RPCInterface/#682c65afe534
--- a/main.cpp	Sat Aug 18 07:26:48 2012 +0000
+++ b/main.cpp	Wed Aug 22 05:10:09 2012 +0000
@@ -1,48 +1,120 @@
-#include "mbed.h"
-#include "TextLCD.h"
-#include "EthernetNetIf.h"
-#include "NTPClient.h"
-
-#define NTPServer "ntp.nict.jp"
-
-#if 1
-// Use DHCP
-EthernetNetIf ethif;
-#else
-// Use "static IP address" (Parameters:IP, Subnet mask, Gateway, DNS)
-EthernetNetIf ethif(IpAddr(xx,xx,xx,xx), IpAddr(xx,xx,xx,xx), IpAddr(xx,xx,xx,xx), IpAddr(xx,xx,xx,xx));
-#endif
-
-TextLCD lcd(p24, p26, p27, p28, p29, p30);
-
-NTPClient ntp;
-
-int main()
-{
-    time_t ctTime;
-    char buffer[32];
-
-    lcd.cls();
-    lcd.locate(0,0);
-    lcd.printf("Program Start");
-
-    if (ethif.setup()) {
-        error("Ethernet setup failed.");
-        return 1;
-    }
-
-    IpAddr ethIp=ethif.getIp();
-    lcd.locate(0,0);
-    lcd.printf("%3d.%3d.%3d.%3d", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
-    Host server(IpAddr(), 123, NTPServer);
-    ntp.setTime(server);
-    //UTC-->JST +9Hour(32400Sec)
-    ctTime = time(NULL);
-    ctTime+=32400;
-    set_time(ctTime);
-    ctTime = time(NULL);
-    strftime(buffer,32,"%x %X",localtime(&ctTime));
-    printf("%s \n",buffer);
-    printf("finish \n");
-
-}
+#include "mbed.h"
+#include "MSCFileSystem.h"
+#include "TextLCD.h"
+#include "EthernetNetIf.h"
+#include "NTPClient.h"
+#include "HTTPServer.h"
+#include "RPCVariable.h"
+#include "RPCFunction.h"
+
+#define NTPServer "ntp.cc.yamaguchi-u.ac.jp"
+
+#if 1
+// Use DHCP
+EthernetNetIf ethif;
+#else
+// Use "static IP address" (Parameters:IP, Subnet mask, Gateway, DNS)
+EthernetNetIf ethif(IpAddr(xx,xx,xx,xx), IpAddr(xx,xx,xx,xx), IpAddr(xx,xx,xx,xx), IpAddr(xx,xx,xx,xx));
+#endif
+
+TextLCD lcd(p24, p26, p27, p28, p29, p30);
+MSCFileSystem msc("usb");
+LocalFileSystem local("local");
+DigitalOut led1(LED1,"led1");
+DigitalOut led2(LED2,"led2");
+DigitalOut led3(LED3,"led3");
+DigitalOut led4(LED4,"led4");
+AnalogIn ain(p15,"ain");
+float temp;
+time_t ctTime;
+
+void lastdate(char *input,char *output);
+NTPClient ntp;
+HTTPServer svr;
+
+RPCVariable<float> rpcv(&temp,"Temp");
+RPCFunction rpcf(&lastdate,"LastDate");
+
+void lastdate(char *input,char *output)
+{
+    if (input[0]=='0')led4=0;
+    if (input[0]=='1')led4=1;
+    char ldate[32];
+    strftime(ldate,32,"%x %X",localtime(&ctTime));
+    strcpy(output,ldate);
+}
+
+void mesure_temp()
+{
+    char buffer[9];
+    temp=ain*3.3*100.0;
+
+    ctTime = time(NULL);
+    strftime(buffer,9,"%X",localtime(&ctTime));
+    lcd.locate(0,1);
+    lcd.printf("%s %4.1fDeg",buffer,temp);
+
+    char filename[23];
+    strftime(filename,23,"/usb/data/%Y%m%d.dat",localtime(&ctTime));
+    FILE *fp= fopen(filename, "a");
+    if ( fp == NULL ) {
+        printf("Could not open file for write\n");
+    } else {
+        fprintf(fp, "%s , %4.1f \r\n",buffer,temp);
+    }
+    fclose(fp);
+}
+
+int main()
+{
+    time_t ctTime;
+    char buffer[32];
+
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Program Start");
+
+    if (ethif.setup()) {
+        error("Ethernet setup failed.");
+        return 1;
+    }
+
+    IpAddr ethIp=ethif.getIp();
+    lcd.locate(0,0);
+    lcd.printf("%3d.%3d.%3d.%3d", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
+    Host server(IpAddr(), 123, NTPServer);
+    ntp.setTime(server);
+    //UTC-->JST +9Hour(32400Sec)
+    ctTime = time(NULL);
+    ctTime+=32400;
+    set_time(ctTime);
+    ctTime = time(NULL);
+    strftime(buffer,32,"%x %X",localtime(&ctTime));
+    printf("%s \n",buffer);
+    printf("finish \n");
+
+    Base::add_rpc_class<DigitalOut>();
+    Base::add_rpc_class<AnalogIn>();
+    FSHandler::mount("/local", "/" );
+    svr.addHandler<RPCHandler>("/rpc");
+    svr.addHandler<FSHandler>("/");
+    svr.addHandler<SimpleHandler>("/hello");
+    svr.bind(80);
+
+    Timer tm;
+    Timer tm2;
+    tm.start();
+    tm2.start();
+    while (true) {
+        Net::poll();
+        if (tm.read()>.5) {
+            led1=!led1; //Show that we are alive
+            tm.start();
+        }
+        if (tm2.read()>5) {
+            led2=!led2;
+            tm2.start();
+            mesure_temp();
+        }
+    }
+}