Send messages continuously instead of all at once.

620 views
Skip to first unread message

Luis Henrique

unread,
Sep 22, 2015, 4:03:44 PM9/22/15
to OMNeT++ Users
Greetings. 

I have a simulation which should work like this. 

* 2 sensors:
    - dbSyncSensor: receives data from other sensors and stores in MySQL.
    - defaultSensor: reads data from the environment and send to dbSyncSensor.

The defaultSensor should report his readings every X seconds and send them to dbSyncSensor every time a new reading is made. That should be done indefinitely. To do so, the code that generates the reading and send them is looped within a while that contains the part where the reading is generated, the send function and a sleep() function. 

What seems to be happening is that when simulation starts the loop is called, exhausted and THEN ALL the messages generated are transmitted all at once to the other sensor. 

To avoid that, what I tried:
- created a compount module with 2 submodules
- the first submodule. when simulation is started, create a message and send to the second submodule
- the second submodule receives the message via handleMessage() and within this function is the looped code that creates the readings, which is triggered.

What's happening is that even with this McGuyver I made the sensor still executes the whole loop and only then sends all the messages.

How can I make it send them consinuously?

The project files are attached. 
DefaultWirelessSensor.cc
omnetpp.ini
package.ned

Alfonso Ariza Quintana

unread,
Sep 23, 2015, 3:50:03 AM9/23/15
to omn...@googlegroups.com

You are blended simulation with the posix API.

 

Sleep is part of the posix API and interrupt the process for 3 seconds, but it doesn’t increase the simulation timer. The second send should be sendDelayed, you can remove the sleep, except if for an unknown reason you need to sleep the process

 

 

 

 

void interface::handleMessage(cMessage *msg){

 

    EV << "interface: New message received!" << msg;

 

        cMessage *msg2 = new cMessage("Um");

 

        send(msg2, "out");

 

        cMessage *msg3 = new cMessage("Dois");

 

        sendDelayed(msg3,3.0,"out");

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/omnetpp.
For more options, visit https://groups.google.com/d/optout.

Rudolf Hornig

unread,
Sep 23, 2015, 5:10:35 AM9/23/15
to OMNeT++ Users, aari...@hotmail.com
Yep, Ariza is right. 

In addition, if you want to do this loop indefinitely while the time is passing, the way to do it is to schedule a self event (timer) that kicks in every X second. Test if the received message is your own self timer and if it is, send out the measurement message + reschedule the self message for t+X so your process will be woken up again by the scheduler.

To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+unsubscribe@googlegroups.com.

Luis Henrique

unread,
Sep 23, 2015, 12:52:40 PM9/23/15
to OMNeT++ Users, aari...@hotmail.com
Hi

I implemented the functionality and is working, thank you all =)

However, although the messages are transmitted continuously through the network while time passes they seem to "stop" when they reach the destination node and its handleMessage() function are not called to process the messages. Only when the transmissions cease the messages are processed all at once. Why they don't get processed as they arrive?

Files of the updated project:

Rudolf Hornig

unread,
Sep 24, 2015, 5:17:29 AM9/24/15
to OMNeT++ Users, aari...@hotmail.com


On Wednesday, 23 September 2015 18:52:40 UTC+2, Luis Henrique wrote:
Hi

I implemented the functionality and is working, thank you all =)

Your code is definitely wrong. Your init function should just create a *single* event and schedule that for t=0. In your handle message youshould:
a) reschedule the received self message to the next measurement tick (i.e. simTime()+dT)
b) send out your sensor message to the other node.

In an other thread Ariza gave a proper code skeleton for this.

Luis Henrique

unread,
Sep 25, 2015, 7:58:24 AM9/25/15
to OMNeT++ Users, aari...@hotmail.com
I did the proposed changes and it worked. Now the sensors generates readings while time passes and the dbSyncSensor process the messages real time when they arrive. 

Thank you again Rudolf and Ariza for the instructions (and patience).

Best regards. 
Reply all
Reply to author
Forward
0 new messages