zzz
Dependencies: C12832_lcd ConfigFile LM75B WiflyInterface2 mbed-rtos mbed
Fork of Xbee_Hello_World_B by
Revision 3:623e2b67ebaa, committed 2016-12-16
- Comitter:
- kingkingyyk
- Date:
- Fri Dec 16 02:56:13 2016 +0000
- Parent:
- 2:ae1a5862504b
- Commit message:
- First commit
Changed in this revision
diff -r ae1a5862504b -r 623e2b67ebaa ConfigFile.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConfigFile.lib Fri Dec 16 02:56:13 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/shintamainjp/code/ConfigFile/#f6ceafabe9f8
diff -r ae1a5862504b -r 623e2b67ebaa EthernetInterface.lib --- a/EthernetInterface.lib Fri Sep 16 15:36:31 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#183490eb1b4a
diff -r ae1a5862504b -r 623e2b67ebaa LM75B.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM75B.lib Fri Dec 16 02:56:13 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/neilt6/code/LM75B/#7ac462ba84ac
diff -r ae1a5862504b -r 623e2b67ebaa WiflyInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WiflyInterface.lib Fri Dec 16 02:56:13 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/kingkingyyk/code/WiflyInterface2/#9fc0bb21c723
diff -r ae1a5862504b -r 623e2b67ebaa main.cpp --- a/main.cpp Fri Sep 16 15:36:31 2016 +0000 +++ b/main.cpp Fri Dec 16 02:56:13 2016 +0000 @@ -1,86 +1,125 @@ #include "mbed.h" -#include "xbee.h" #include "C12832_lcd.h" +#include "LM75B.h" #include <string> -#include "EthernetInterface.h" +#include "WiflyInterface.h" +#include "rtos.h" +#include "LM75B.h" + +class Watchdog { +public: +// Load timeout value in watchdog timer and enable + void kick(float s) { + LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK + uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 + LPC_WDT->WDTC = s * (float)clk; + LPC_WDT->WDMOD = 0x3; // Enabled and Reset + kick(); + } +// "kick" or "feed" the dog - reset the watchdog timer +// by writing this required bit pattern + void kick() { + LPC_WDT->WDFEED = 0xAA; + LPC_WDT->WDFEED = 0x55; + } +}; + +// Setup the watchdog timer +Watchdog wdt; -xbee xbee1(p9,p10,p30); //Initalise xbee_lib +WiflyInterface wifly(p9, p10, p30, p29, "SSID", "PASSWORD", WPA); +AnalogIn ain(p17); C12832_LCD lcd; -DigitalOut LanLED(LED1); -DigitalOut XbeeLED(LED2); -DigitalOut LanDataLED(LED3); -EthernetInterface eth; +DigitalOut led [] ={(LED1),(LED2),(LED3),(LED4)}; +LM75B tempSensor(p28,p27); +const char *server_ip="192.168.10.2"; +const int server_port=40000; +char status_data[100]; + +const char* tempFormat="0;TechRoomB_Monitor;BlockB_Temperature;%f"; +void sendTempReading () { + led[2]=1; + TCPSocketConnection conn; + + for (int i=0;i<100;i++) status_data[i]=0; + snprintf(status_data,100,tempFormat,(((float)tempSensor)+55)/175); -bool setupEthernet() { + led[3]=1; + if (conn.connect(server_ip,server_port)==0 && conn.send_all(status_data,100)>=0); wdt.kick(); + led[3]=0; + + wait(0.1); + conn.close(); + led[2]=0; +} + +const char* currentFormat="0;TechRoomB_Monitor;BlockB_AirCondCurrent;%f"; +void sendCurrentReading () { + led[0]=1; + TCPSocketConnection conn; + + float max=0.0; + time_t start=time(NULL); + while (time(NULL)-start<2) { + if (ain>0 && ain<0.3 && ain>max) max=ain; + } + lcd.cls(); lcd.locate(0,0); - lcd.printf("Start Ethernet Setup\n"); + lcd.printf("Current : %f",max); + + for (int i=0;i<100;i++) status_data[i]=0; + snprintf(status_data,100,currentFormat,max*3); + + led[1]=1; + if (conn.connect(server_ip,server_port)==0 && conn.send_all(status_data,100)>=0); wdt.kick(); + led[1]=0; - eth.init("172.16.0.2","255.255.0.0","172.16.0.1"); - if(eth.connect()!=0) { - lcd.printf("Not connected!\n"); - return false; - } else { - lcd.printf("IP Address : %s\n", eth.getIPAddress()); - return true; + wait(0.1); + conn.close(); + led[0]=0; +} + +void sendReading() { + sendCurrentReading(); + wait(3.0); + sendTempReading(); +} + +void setupWifly() { + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Start WiFi Setup\n"); + + wifly.init(); +} + +void checkWiflyConnection() { + if (!wifly.is_associated()) { + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Reconnecting..."); + while (!wifly.connect()); + lcd.cls(); + lcd.locate(0,0); + lcd.printf("IP Address : %s\n", wifly.getIPAddress()); } } -void setupXbee() { - lcd.cls(); - lcd.locate(0,0); - lcd.printf("Start Xbee Setup\n"); - xbee1.Reset(); - xbee1.ConfigMode(); - xbee1.ResetConfig(); - xbee1.SetPanId(123); - xbee1.ExitConfigMode(); - lcd.printf("Done Setup!\n"); +void getCommand() { + checkWiflyConnection(); + wdt.kick(120.0); + while (1) { + sendReading(); + wait(60.0); + } } int main() { - bool flag=true; - flag=setupEthernet(); - LanLED=flag; - wait(0.5); - setupXbee(); + set_time(0); + mbed_interface_disconnect(); //Disable debugging to improve ADC precision. | Comment this if you need debugging via serial. - if (flag) { - UDPSocket socket; - socket.init(); - Endpoint server; - server.set_address("172.16.0.1",40000); - - int count=0; - char read_data[202]; //Xbee buffer size is 202 bytes - - while(1) { - char temp[202]; - XbeeLED=1; - xbee1.RecieveData(temp,10); //Read data from the XBee - XbeeLED=0; - for (int i=0;i<10 && temp[i]!='\0';i++) { - if (temp[i]=='|') { - count=0; - } else if (temp[i]=='&') { - string real_data=""; - for (int i2=0;i2<count;i2++) { - real_data+=read_data[i2]; - } - lcd.cls(); - lcd.locate(0,3); - lcd.printf("%s",real_data); - LanDataLED=1; - socket.sendTo(server,read_data,real_data.length()); - LanDataLED=0; - count=0; - for (int i2=0;i2<202;i2++) { - read_data[i2]='\0'; - } - } else { - read_data[count++]=temp[i]; - } - } - } - } + setupWifly(); + + getCommand(); } \ No newline at end of file
diff -r ae1a5862504b -r 623e2b67ebaa mbed-rtos.lib --- a/mbed-rtos.lib Fri Sep 16 15:36:31 2016 +0000 +++ b/mbed-rtos.lib Fri Dec 16 02:56:13 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#3da5f554d8bf +https://mbed.org/users/mbed_official/code/mbed-rtos/#ac4f3830f9ff
diff -r ae1a5862504b -r 623e2b67ebaa mbed.bld --- a/mbed.bld Fri Sep 16 15:36:31 2016 +0000 +++ b/mbed.bld Fri Dec 16 02:56:13 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/2e9cc70d1897 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/082adc85693f \ No newline at end of file
diff -r ae1a5862504b -r 623e2b67ebaa xbee_lib.lib --- a/xbee_lib.lib Fri Sep 16 15:36:31 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/tristanjph/code/xbee_lib/#81b7110f5877