first commit

Dependencies:   C12832_lcd DigiLogger LM75B XBeeLib2 mbed

Fork of XBee802_Send_Data by Digi International Inc.

Files at this revision

API Documentation at this revision

Comitter:
kingkingyyk
Date:
Fri Dec 16 02:59:48 2016 +0000
Parent:
10:73901166c6f4
Commit message:
first commit

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
DigiLogger.lib Show annotated file Show diff for this revision Revisions of this file
LM75B.lib Show annotated file Show diff for this revision Revisions of this file
XBeeLib.lib Show annotated file Show diff for this revision Revisions of this file
config.h 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 73901166c6f4 -r 44571f2b239e C12832_lcd.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Fri Dec 16 02:59:48 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
diff -r 73901166c6f4 -r 44571f2b239e DigiLogger.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DigiLogger.lib	Fri Dec 16 02:59:48 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Digi-International-Inc/code/DigiLogger/#58c5158b5120
diff -r 73901166c6f4 -r 44571f2b239e LM75B.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LM75B.lib	Fri Dec 16 02:59:48 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/neilt6/code/LM75B/#7ac462ba84ac
diff -r 73901166c6f4 -r 44571f2b239e XBeeLib.lib
--- a/XBeeLib.lib	Fri Jul 29 12:11:33 2016 +0200
+++ b/XBeeLib.lib	Fri Dec 16 02:59:48 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/Digi-International-Inc/code/XBeeLib/#b5f4a0e92249
+https://developer.mbed.org/users/kingkingyyk/code/XBeeLib2/#b04b7e0672a9
diff -r 73901166c6f4 -r 44571f2b239e config.h
--- a/config.h	Fri Jul 29 12:11:33 2016 +0200
+++ b/config.h	Fri Dec 16 02:59:48 2016 +0000
@@ -21,15 +21,15 @@
 
 #define SYNC_OPS_TIMEOUT_MS         2000
 
-//#define RADIO_TX                NC /* TODO: specify your setup's Serial TX pin connected to the XBee module DIN pin */
-//#define RADIO_RX                NC /* TODO: specify your setup's Serial RX pin connected to the XBee module DOUT pin */
+#define RADIO_TX                p9 /* TODO: specify your setup's Serial TX pin connected to the XBee module DIN pin */
+#define RADIO_RX                p10 /* TODO: specify your setup's Serial RX pin connected to the XBee module DOUT pin */
 //#define RADIO_RTS               NC /* TODO: specify your setup's Serial RTS# pin connected to the XBee module RTS# pin */
 //#define RADIO_CTS               NC /* TODO: specify your setup's Serial CTS# pin connected to the XBee module CTS# pin */
-//#define RADIO_RESET             NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's reset pin */
+#define RADIO_RESET             p30 /* TODO: specify your setup's GPIO (output) connected to the XBee module's reset pin */
 //#define RADIO_SLEEP_REQ         NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's SLEEP_RQ pin */
 //#define RADIO_ON_SLEEP          NC /* TODO: specify your setup's GPIO (input) connected to the XBee module's ON_SLEEP pin */
-//#define DEBUG_TX                NC /* TODO: specify your setup's Serial TX for debugging */
-//#define DEBUG_RX                NC /* TODO: specify your setup's Serial RX for debugging (optional) */
+#define DEBUG_TX                NC /* TODO: specify your setup's Serial TX for debugging */
+#define DEBUG_RX                NC /* TODO: specify your setup's Serial RX for debugging (optional) */
 
 #if !defined(RADIO_TX)
     #error "Please define RADIO_TX pin"
diff -r 73901166c6f4 -r 44571f2b239e main.cpp
--- a/main.cpp	Fri Jul 29 12:11:33 2016 +0200
+++ b/main.cpp	Fri Dec 16 02:59:48 2016 +0000
@@ -1,84 +1,83 @@
-/**
- * Copyright (c) 2015 Digi International Inc.,
- * All rights not expressly granted are reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
- * =======================================================================
- */
+#include "mbed.h"
+#include "C12832_lcd.h"
+#include "LM75B.h"
+#include "XBeeLib.h"
 
-#include "mbed.h"
-#include "XBeeLib.h"
 #if defined(ENABLE_LOGGING)
 #include "DigiLoggerMbedSerial.h"
 using namespace DigiLog;
 #endif
 
-#define REMOTE_NODE_ADDR64_MSB  ((uint32_t)0x0013A200)
-
-#error "Replace next define with the LSB of the remote module's 64-bit address (SL parameter)"
-#define REMOTE_NODE_ADDR64_LSB  ((uint32_t)0x01234567)
-
-#error "Replace next define with the remote module's 16-bit address (MY parameter)"
-#define REMOTE_NODE_ADDR16      ((uint16_t)0x1111)
-
-#define REMOTE_NODE_ADDR64      UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
+#define REMOTE_NODE_ADDR16      ((uint16_t)0x0)
 
 using namespace XBeeLib;
 
-Serial *log_serial;
+const int NODE_MODE=0; //0 = send reading, 1 = receive command
+LM75B tempSensor(p28,p27);
+C12832_LCD lcd;
+AnalogIn current(p17);
+DigitalOut leds [] ={(LED1),(LED2)};
+XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
+const RemoteXBee802 remoteDevice16b = RemoteXBee802(REMOTE_NODE_ADDR16);
+char send_data [98];
 
-static void send_broadcast_data(XBee802& xbee)
-{
-    const char data[] = "send_broadcast_data";
-    const uint16_t data_len = strlen(data);
+void clear_send_data() {
+    for (int i=0;i<98;i++) send_data[i]=0;
+}
 
-    const TxStatus txStatus = xbee.send_data_broadcast((const uint8_t *)data, data_len);
+int calculate_send_data_size() {
+    for (int i=0;i<98;i++) if (send_data[i]==0) return i;
+    return 98;
+}
 
-    if (txStatus == TxStatusSuccess)
-        log_serial->printf("send_broadcast_data OK\r\n");
-    else
-        log_serial->printf("send_broadcast_data failed with %d\r\n", (int) txStatus);
+void sendTemp(const char* format, XBee802& xbee, const RemoteXBee802& remoteDevice) {
+    leds[0]=1;
+    snprintf(send_data,98,format,(tempSensor.temp()+55)/(175));
+    
+    xbee.send_data(remoteDevice,(const uint8_t *)send_data,calculate_send_data_size());
+    clear_send_data();
+    leds[0]=0;
 }
 
-static void send_data_to_remote_node(XBee802& xbee, const RemoteXBee802& RemoteDevice)
-{
-    const char data[] = "send_data_to_remote_node";
-    const uint16_t data_len = strlen(data);
-
-    const TxStatus txStatus = xbee.send_data(RemoteDevice, (const uint8_t *)data, data_len);
-
-    if (txStatus == TxStatusSuccess)
-        log_serial->printf("send_data_to_remote_node OK\r\n");
-    else
-        log_serial->printf("send_data_to_remote_node failed with %d\r\n", (int) txStatus);
+void sendCurrent(const char* format, XBee802& xbee, const RemoteXBee802& remoteDevice) {
+    leds[1]=1;
+    float max=0.0;
+    time_t start=time(NULL);
+    while (time(NULL)-start<2) {
+        float value=1.0-current;
+        if (value>0 && value>max) max=value;
+    }
+    
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Waterflow : %f L/min",max*19.8);
+    snprintf(send_data,98,format,max);
+            
+    xbee.send_data(remoteDevice,(const uint8_t *)send_data,calculate_send_data_size());
+    clear_send_data();
+    leds[1]=0;
 }
 
+const char tempFormat []="0;Toilet_Monitor;ToiletTemperature;%f";
+const char currentFormat []="0;Toilet_Monitor;ToiletWaterflow;%f";
+
+void sendReadings () {
+    while (1) {
+        sendTemp(tempFormat,xbee,remoteDevice16b);
+        wait(0.1);
+        sendCurrent(currentFormat,xbee,remoteDevice16b);
+        wait(58.0);
+    }
+}
 int main()
 {
-    log_serial = new Serial(DEBUG_TX, DEBUG_RX);
-    log_serial->baud(9600);
-    log_serial->printf("Sample application to demo how to send unicast and broadcast data with the XBee802\r\n\r\n");
-    log_serial->printf(XB_LIB_BANNER);
-
-#if defined(ENABLE_LOGGING)
-    new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
-#endif
-
-    XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
-
+    set_time(0);
+    mbed_interface_disconnect(); //Disable debugging to improve ADC precision. | Comment this if you need debugging via serial.
+    
     RadioStatus radioStatus = xbee.init();
     MBED_ASSERT(radioStatus == Success);
-
-    const RemoteXBee802 remoteDevice64b = RemoteXBee802(REMOTE_NODE_ADDR64);
-    const RemoteXBee802 remoteDevice16b = RemoteXBee802(REMOTE_NODE_ADDR16);
-
-    send_broadcast_data(xbee);
-    send_data_to_remote_node(xbee, remoteDevice64b);
-    send_data_to_remote_node(xbee, remoteDevice16b);
-
-    delete(log_serial);
-}
+    
+    if (NODE_MODE==0) {
+        sendReadings();
+    } else {}
+}
\ No newline at end of file
diff -r 73901166c6f4 -r 44571f2b239e mbed.bld
--- a/mbed.bld	Fri Jul 29 12:11:33 2016 +0200
+++ b/mbed.bld	Fri Dec 16 02:59:48 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file