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: ASyncTicker EthernetInterface WebSocketClient mbed-rtos mbed MbedJSONValue xbee_lib
Revision 7:7039646b7083, committed 2014-06-18
- Comitter:
- ammanvedi
- Date:
- Wed Jun 18 17:44:49 2014 +0000
- Parent:
- 6:c1bd3fadce09
- Child:
- 8:0d7ab8af0e59
- Commit message:
- hi wiktor
Changed in this revision
--- a/btNode.cpp Mon Feb 03 12:07:53 2014 +0000
+++ b/btNode.cpp Wed Jun 18 17:44:49 2014 +0000
@@ -2,13 +2,51 @@
#include "mbed.h"
#include "xbee.h"
#include "xbeeFrame.h"
+#include "MbedJSONValue.h"
const char btNode::ADDRESS[8] = {0x00, 0x13, 0xA2, 0x00, 0x40, 0x9B, 0x6D, 0xB0};
-btNode::btNode(int D_ID){
+btNode::btNode(int D_ID, std::string D_NAME, std::string H_ID){
ID = D_ID;
+ DeviceName = D_NAME;
+ DisplayString = "{Apple:$1;}";
+ HubID = H_ID;
+
}
+
+MbedJSONValue btNode::GetAsJSON()
+{
+ MbedJSONValue thisnode;
+
+ //std::string s;
+
+ // fill the object
+ thisnode["device_id"] = ID;
+ thisnode["device_name"] = DeviceName;
+ thisnode["device_dataset"] = DisplayString;
+ thisnode["device_hub_id"] = HubID;
+
+ // serialize it into a JSON string
+ //s = request.serialize();
+
+ return thisnode;
+}
+
+std::string btNode::getName()
+{
+ return DeviceName;
+}
+
+std::string btNode::getDisplayString()
+{
+ return DisplayString;
+}
+
+void btNode::setName(std::string newname)
+{
+ DeviceName = newname;
+}
std::string btNode::SendMessage(std::string msg) {
--- a/btNode.h Mon Feb 03 12:07:53 2014 +0000
+++ b/btNode.h Wed Jun 18 17:44:49 2014 +0000
@@ -1,18 +1,25 @@
#ifndef BT_DEVICE
#define BT_DEVICE
-
+#include "MbedJSONValue.h"
#include <string>
#include "xbee.h"
#include "xbeeFrame.h"
class btNode {
public:
- btNode(int D_ID);
+ btNode(int D_ID, std::string D_NAME, std::string H_ID);
std::string SendMessage(std::string msg);
int getID(){return ID;};
+ MbedJSONValue GetAsJSON();
+ std::string getName();
+ std::string getDisplayString();
+ void setName(std::string newname);
private:
int ID;
+ std::string DisplayString;
+ std::string DeviceName;
+ std::string HubID;
static const char ADDRESS[8];
//const char dest_address[8] ={0x00, 0x13, 0xA2, 0x00, 0x40, 0x9B, 0x6D, 0xB0};
};
--- a/main.cpp Mon Feb 03 12:07:53 2014 +0000
+++ b/main.cpp Wed Jun 18 17:44:49 2014 +0000
@@ -9,7 +9,9 @@
#include <string>
#include "btNode.h"
#include <map>
+#include <utility>
#define PORT 80
+const std::string HUBID = "1";
// status leds
// led 1
@@ -25,7 +27,43 @@
EthernetInterface ethernet;
Websocket ws("ws://192.168.0.4:8080/");
+bool sync_devices()
+{
+ MbedJSONValue sync_data;
+ std::string sync_string;
+
+ // fill the object
+ sync_data["TYPE"] = "SYNC";
+ sync_data["ORIGIN"] = "HUB";
+ sync_data["ID"] = "N/A";
+
+ //sync_data["DATA"] = "N/A";
+ //iterate over local nodes and send node list to svr over socket
+
+ // map<char, int>::iterator p;
+
+ int index = 0;
+
+for (std::map<int, btNode>::iterator it = BTnodes.begin(); it != BTnodes.end(); ++it)
+{
+ MbedJSONValue device = it->second.GetAsJSON();
+ printf("dev : %s\n\r", device.serialize());
+ sync_data["DEVICES"][index] = device.serialize();
+ index++;
+}
+ sync_data["COUNT"] = index;
+ sync_data["STATUS"] = "0";
+
+ sync_string = sync_data.serialize();
+
+ ws.send((char *)sync_string.c_str());
+
+ // serialize it into a JSON string
+
+
+return true;
+}
void pull_updates()
{
@@ -96,8 +134,10 @@
int main()
{
-
- btNode b(30);
+ //add a registered device to the device array
+ btNode a(1, "msp430-homer", HUBID);
+ btNode b(30, "mp430-adam", HUBID);
+ BTnodes.insert(pair<int, btNode>(1,a));
BTnodes.insert(pair<int, btNode>(30,b));
led_ethernet = 0;
@@ -128,6 +168,8 @@
Timer timer;
timer.start();
+
+ sync_devices();
// every <interval> seconds call to the server to pull updates
while (true)