-3

I would like to exchange data under mixim framework node Host80211{ }, but it first needs to check the battery power of each node as in the example code:

if (node1.check_battery() >= node2.check_battery()) {
    send(node1.out-->node2.in);
}

How and where do I implement the code to check the condition ?

Thanks

user4786271
  • 1,555
  • 13
  • 18
  • it sounds like you need a central entity which has an overview of the network and can compare the battery level of different nodes and then tell them what to do? that's what I infer from your mock code, is that what you want to achieve? – user4786271 May 31 '15 at 13:55
  • Actually i am newbie in WSN.i am trying to do simple coding on sensor node.my concept is simple. if node1 has more energy then node2 it sends data as node1->node2 and vice-versa. i need the mock code. Thanks – Abir Hossain Jun 01 '15 at 04:09
  • Actually is it feasible to do it practically ? – Abir Hossain Jun 01 '15 at 09:19
  • First of all you would need to identify if MIXIM frameworks, offers such a central entity which is aware of the different battery levels. If yes then each of your nodes car query this central entity to learn the battery level of another node and then make the sending decision. If there is not such a module, then you might need to define a node which you could call `server` which holds a table of battery levels, and periodically each of your nodes would provide battery charge levels to it, and then they could query it for battery level and make further decisions... – user4786271 Jun 01 '15 at 10:44
  • since I am not familiar with those MIXIM modules, maybe it would be useful for you to start from some existing example for WSN nodes. if you are a total newbie then start from the TicToc tutorial: https://omnetpp.org/doc/omnetpp/tictoc-tutorial/ – user4786271 Jun 01 '15 at 10:46
  • Thanks for your valuable suggestion. How do i implement of your concept as "a server that holds a table of battery levels and each node periodically sens its own charge level". – Abir Hossain Jun 02 '15 at 04:17
  • how much experience you have in OMNeT++ and C++? have you done the TicToc tutorial? – user4786271 Jun 02 '15 at 09:12
  • yes i have complete tictoc tutorial.now i am currently study on mixim base coding on nic , phy layer connection , session ,transport , application layer connection of a host in wireless node. Thanks.your help is appreciated. – Abir Hossain Jun 03 '15 at 00:46
  • you can create central a node in your network which accepts messages from the other nodes. And have all of the other nodes send battery levels to this node every 1 second (with a self-message which tells them to send `battery-info` to the `central-node`... In the central node you can save this info in an std::map with sender's id as key, and provide a `query(nodeID)` function which allows regular nodes to learn the last reported battery level of a certain node, and thus make sending decisions. – user4786271 Jun 03 '15 at 08:44

1 Answers1

0

As I have explained in my comments: you can have a central entity which the other nodes can query and then make sending decision based on that. This central entity can be another node in the sensor network or simply a class which the nodes can instantiate.

For example:

class BatteryMonitor: public cSimpleModule
{
    public:
        BatteryMonitor();

        void report_battery(const std::string& nodeID, float batteryLevel,) 
        double check_battery(const std::string& nodeID);


    protected:
        std::map<std::string, double> batteryLevels;
};

You can set a self-message every 1 second to your sensor nodes, to make sure that they report the most recent battery level .

In your nodes you can do something similar to your code:

    if (batteryMonitor->check_battery(this->myID) >= batteryMonitor->check_battery(otherNodeID)) {
        send(thisMessage, otherNode);
}
user4786271
  • 1,555
  • 13
  • 18
  • sir , would you please clarify that where i put the following code ? is it in .CC file of the wireless node or in the module of the batterystats.cc under the mixim module ? i put the code in wirelessNode.cc file but it shows "Node is not declare in this scope? – Abir Hossain Jun 21 '15 at 04:45
  • First you will need to create a new module and then each of your nodes should have a pointer to that module to be able to query it. In my answer I have written **In your nodes...** http://stackoverflow.com/questions/30644495/oop-class-design-in-c – user4786271 Jun 26 '15 at 17:09