Using Ethernet Interface to send temperature/humidity info to client
Dependencies: EthernetInterface SDFileSystem SHTx mbed-rtos mbed
Revision 0:e26dfd507000, committed 2013-10-17
- Comitter:
- airaylee
- Date:
- Thu Oct 17 23:59:17 2013 +0000
- Child:
- 1:788d545c9cd1
- Commit message:
- Original Version;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Thu Oct 17 23:59:17 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#cba86db5ab96
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Thu Oct 17 23:59:17 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SHTx.lib Thu Oct 17 23:59:17 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/NegativeBlack/code/SHTx/#8465801be23f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Oct 17 23:59:17 2013 +0000 @@ -0,0 +1,84 @@ + +#include "mbed.h" +#include "SHTx/sht15.hpp" +#include "SDFileSystem.h" +#include "EthernetInterface.h" + +//SPI-mosi,miso,sclk,DigitalOut-cs, name used to access the filesystem +SDFileSystem sd(p5, p6, p7, p8, "sd1"); + +//Terminal Port to display the file back +Serial pc(USBTX, USBRX); +DigitalOut busy(LED1); + +// Use p28-sda--data,p27-scl--sck +SHTx::SHT15 sensor(p28, p27); + +EthernetInterface eth; +#define ECHO_SERVER_PORT 7 + +int main() { + + /*FILE *fw = fopen("/sd1/mydir/sdtest.txt", "w"); + if(fw == NULL) { + pc.printf("Could not open file for write\n"); + } + else{ + fprintf(fw, "Hello SD file World!LOLOLOL\n"); + fclose(fw); + } + //Begin reading from the SD file + pc.printf("Begin reading from the SD file\n"); + FILE *fr = fopen("/sd1/mydir/sdtest.txt", "r"); + if(fr== NULL) { + pc.printf("Could not open file for read\n"); + } + else{ + while(!feof(fr)){ + pc.putc(fgetc(fr)); + } + fclose(fr); + } + */ + + // Speed things up a bit. + sensor.setOTPReload(false); + sensor.setResolution(true); + + eth.init(); //Use DHCP + eth.connect(7000);//Longer timeout here + //print out the MAC address first + printf("MAC Address is %s\r\n", eth.getMACAddress()); + printf("IP Address is %s\r\n", eth.getIPAddress()); + //IP address is 130.207.234.205 + + + TCPSocketServer server; + server.bind(ECHO_SERVER_PORT); + server.listen(); + + while(1) { + printf("\nWait for new connection...\r\n"); + TCPSocketConnection client; + server.accept(client); + client.set_blocking(false); // Timeout after (5)s + + printf("Connection from: %s\r\n", client.get_address()); + + busy = true; + sensor.update(); + busy = false; + char buffer[256]={0}; + + // Temperature in celcius + sensor.setScale(false); + sprintf(buffer,"Temperature [ %3.2f C ]\r\nHumdity [ %3.2f %% ]\r\n\n", sensor.getTemperature(), sensor.getHumidity()); + + int n = sizeof(buffer); + client.send_all(buffer, n); + + client.close(); + printf(" Connection over\r\n"); + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Oct 17 23:59:17 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Oct 17 23:59:17 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file