Using AODV in a wired simulation - omnet++

I am trying to use AODV in a wired simulation but I can't make it work, is it possible to link 2 AODVRouters by wire and use the AODV protocol?? or should I use 2 standardhost and modify the AODVrouting.cc??
EDIT:
I just simulate the AODV simpleRREQ example using standardhosts instead of AODVrouters and using the debug mode it crashes in this piece of code:
void AODVRouting::sendAODVPacket(AODVControlPacket *packet, const L3Address& destAddr, unsigned int timeToLive, double delay)
{INetworkProtocolControlInfo *networkProtocolControlInfo = addressType->createNetworkProtocolControlInfo();
networkProtocolControlInfo->setHopLimit(timeToLive);
networkProtocolControlInfo->setTransportProtocol(IP_PROT_MANET);
networkProtocolControlInfo->setDestinationAddress(destAddr);
networkProtocolControlInfo->setSourceAddress(getSelfIPAddress());
// TODO: Implement: support for multiple interfaces
InterfaceEntry *ifEntry = interfaceTable->getInterfaceByName("AODV");
networkProtocolControlInfo->setInterfaceId(ifEntry->getInterfaceId());
UDPPacket *udpPacket = new UDPPacket(packet->getName());
udpPacket->encapsulate(packet);
udpPacket->setSourcePort(aodvUDPPort);
udpPacket->setDestinationPort(aodvUDPPort);
udpPacket->setControlInfo(dynamic_cast<cObject *>(networkProtocolControlInfo));
if (destAddr.isBroadcast())
lastBroadcastTime = simTime();
if (delay == 0)
send(udpPacket, "ipOut");
else
sendDelayed(udpPacket, delay, "ipOut");
}
How can I send the AODV packet throw all the ethernet ports of the router?

Related

How to connect TI - CC1101 to NodeMCU Board

I'm trying to get the TI-CC1101 433 MHz Transceiver Module to work with my NodeMCU ESP8266 but I am not sure about the wiring.
Link to the data sheet: LINK
Heres is a link with picture:LINK
I only want to use this Transceiver as a receiver for now so that's my setup:
NodeMCU 3.3 Volt --> VIC of TI-CC110
GND --> GND
NodeMCU D4 (2 in Arduino IDE) --> SI pin of TI-CC110.
I tested the following code with another 433 MHz receiving unit and it worked.
It's the example code of the RC Link Library:
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(2); // Receiver on interrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
}
mySwitch.resetAvailable();
}
}
I get nothing when I'm trying the new module wired the way described above.
Hello the rc switch library does not support the cc1101 module officially. but there is an external driver library which allows to use the cc1101 module with rcswitch. Currently the esp modules are not supported. an update for esp is in planning.
https://github.com/LSatan/RCSwitch-CC1101-Driver-Lib

Solving "redeclared as different kind of symbol" error

I'm currently working on Arduino. I'm working for Lamp using Atmega1284. I saw an example code, ModbusIP_ENC28J60 -> Lamp. I first compiled it without adding anything, it compiled properly. Now, I'm adding WebSocketServer, since I want this to work on websocket too. I added few necessary lines, but I ended up with this error:
error: 'EthernetClass Ethernet' redeclared as different kind of symbol
I don't understand what's wrong with the code or what I should change. Can someone help me with this?
I'm pasting my code here for reference:
#include <EtherCard.h>
#include <Modbus.h>
#include <ModbusIP_ENC28J60.h>
#include <WebSocketsServer.h>
WebSocketsServer webSocketServer = WebSocketsServer(8080);
//Modbus Registers Offsets (0-9999)
const int LAMP1_COIL = 100;
//Used Pins
const int ledPin = 9;
//ModbusIP object
ModbusIP mb;
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) {
switch(type) {
case WStype_DISCONNECTED:
Serial.println("[%u] Disconnected!\n");
break;
case WStype_CONNECTED:
{
//IPAddress ip = webSocket.remoteIP(num);
Serial.println("[%u] Disconnected!\n");
// send message to client
//webSocket.sendTXT(num, "Connected");
}
break;
case WStype_TEXT:
Serial.println("[%u] got text!\n");
// send message to client
// webSocket.sendTXT(num, "message here");
// send data to all connected clients
// webSocket.broadcastTXT("message here");
break;
case WStype_BIN:
Serial.println("[%u] get binary ");
//hexdump(payload, lenght);
// send message to client
// webSocket.sendBIN(num, payload, lenght);
break;
}
}
void setup() {
// The media access control (ethernet hardware) address for the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// The IP address for the shield
byte ip[] = { 192, 168, 0, 120 };
//Config Modbus IP
mb.config(mac, ip);
//Set ledPin mode
pinMode(ledPin, OUTPUT);
// Add LAMP1_COIL register - Use addCoil() for digital outputs
mb.addCoil(LAMP1_COIL);
webSocketServer.begin();
webSocketServer.onEvent(webSocketEvent);
}
void loop() {
//Call once inside loop() - all magic here
mb.task();
//Attach ledPin to LAMP1_COIL register
digitalWrite(ledPin, mb.Coil(LAMP1_COIL));
webSocketServer.loop();
}
Help me to make it work.
You are declaring Ethernet twice. And they are different.
First is probably in the include file Ethercard.h
Second is Modbus.h
In the ModbusIP_ENC28J60 I found in github via Google they declare Ethernet as an array.
Either rename one declaration (e.g. ether vs Ethernet) or eliminate the use of one. Also, considering the include files in your source I would be surprised if there are only two conflicts.
C lesson: Declaring a variable for use by a function, very straightforward. When adding additional modules any name conflicts will cause problems. If you get two variables to agree but are still in the program you will suffer massive debugging headaches because one function will access its variable while the other will have its own, resulting in nothing actually working.
Go back and look at the source files (*.h). Search for "Ethernet" variables. See how they are declared and how they are used. The simplest solution is to pick the latest addition and change Ethernet to ether (as I suggested above).
Good Luck.

UDP server send packet not over multicast ip with boost asio

I'm beginner with boost::asio and udp networking system.
I'm trying to receive many of packet from multicast(239.255.255.251:5353) and I want to send packet multicast(239.255.255.251:5353) for specific device.
I referenced this example from boost
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/example/multicast/receiver.cpp
and I modified that
void handle_receive_from(const boost::system::error_code& error,
size_t bytes_recvd)
{
if (!error)
{
if(mdns_validate_name(data_, bytes_recvd))
{
std::cout.write(data_, bytes_recvd);
std::cout << std::endl;
/** make packet for send **/
socket_.async_send_to(
boost::asio::buffer(data_, length), multi_endpoint_,
boost::bind(&receiver::handle_send, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
else
{
socket_.async_receive_from(
boost::asio::buffer(data_, max_length), multi_endpoint_,
boost::bind(&receiver::handle_receive_from, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
}
}
my problem is packet not over multicast(239.255.255.251:5353). it just sent specific ip(192.168.0.168). I checked wire shark.
I want to send packet again over multicast (239.255.255.251:5353).
please comment!
Unfortunately UDP multicast sending and receiving are completely different.
A receiver uses a local address to select the receiving device: usually set to any. Whilst a sender requires a remote address, i.e. the multicast address. In your case that would be 239.255.255.251.
E.g. from the boost::asio sender example:
class sender
{
public:
sender(boost::asio::io_service& io_service,
const boost::asio::ip::address& multicast_address)
: endpoint_(multicast_address, multicast_port),
socket_(io_service, endpoint_.protocol())
{}
.
.
.
private:
boost::asio::ip::udp::endpoint endpoint_;
boost::asio::ip::udp::socket socket_;
};
BTW the boost::asio UDP example that you reference is very old and for a receiver!
The latest boost::asio UDP sender example is here. However, for your purposes the echo server would be a better starting point.
If you want to see complete example of IPv4 and IPv6 UDP asio comms then have a look at udp_adaptor.hpp here.

ATtiny85 serial communication with multiple inputs

In a project, we try to set up a communication network between three ATtinys, where the first must receive messages from the other two. Those other two tinys are connected to two different pins of the first tiny. The first tiny must then receive two strings from the other tinys, one from each, and send it to an Arduino. For the communication we used SoftwareSerial. We managed to receive and send the input from one tiny, but not from both of them, because we could not find a way to read the input from only one specific pin at a time.
This is the code we used:
#include <SoftwareSerial.h>
const int rx=4;
const int rx2=1;
const int tx=3;
const int tx2=3;
SoftwareSerial mySerial(rx,tx);
SoftwareSerial mySerial2(rx2,tx2);
void setup()
{
pinMode(rx,INPUT);
pinMode(rx2,INPUT);
pinMode(tx,OUTPUT);
mySerial.begin(9600);
mySerial2.begin(9600);
}
void loop()
{
mySerial.listen();
if (mySerial.isListening()) {
mySerial.println("Port One is listening!");
mySerial.println(mySerial.read());
}
else{
mySerial.println("Port One is not listening!");
}
mySerial2.listen();
if (mySerial2.isListening()) {
mySerial2.println("Port Two is listening!");
mySerial2.println(mySerial2.read());
}
else{
mySerial2.println("Port Two is not listening!");
}
delay(500);
}
The code above worked without the part after mySerial2.listen();. Maybe the listen-function of SoftwareSerial does not work on the tinys, but if that is the case, is there another way to listen to a specific input pin?
Or do you have any advice what to do?

How to know when a HID USB/Bluetooth device is connected in Cocoa?

How can I get a simple call back when a HID device, or at last, any USB/Bluetooth device gets connected/disconnected?
I made a simple app that shows the connected joysticks and the pressed buttons/axis for mac in a pretty way. Since I am not very familiar with cocoa yet, I made the UI using a webview, and used the SDL Joystick library.
Everything is working nice, the only problem is that the user needs to scan for new joysticks manually if he/she connects/disconnects something while the program is running.
With a callback, I I can just call the Scan function. I don't want to handle the device or do something fancy, just know when there is something new happening...
Thanks.
Take a look at IOServiceAddMatchingNotification() and related functions. I've only worked with it in the context of serial ports (which are in fact USB to serial adapters, though that doesn't matter), but it should be applicable to any IOKit accessible device. I'm not sure about Bluetooth, but it should at least work for USB devices. Here's a snippet of code I use:
IONotificationPortRef notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(notificationPort),
kCFRunLoopDefaultMode);
CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOSerialBSDServiceValue);
CFRetain(matchingDict); // Need to use it twice and IOServiceAddMatchingNotification() consumes a reference
CFDictionaryAddValue(matchingDict, CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDRS232Type));
io_iterator_t portIterator = 0;
// Register for notifications when a serial port is added to the system
kern_return_t result = IOServiceAddMatchingNotification(notificationPort,
kIOPublishNotification,
matchingDictort,
SerialDeviceWasAddedFunction,
self,
&portIterator);
io_object_t d;
// Run out the iterator or notifications won't start (you can also use it to iterate the available devices).
while ((d = IOIteratorNext(iterator))) { IOObjectRelease(d); }
// Also register for removal notifications
IONotificationPortRef terminationNotificationPort = IONotificationPortCreate(kIOMasterPortDefault);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(terminationNotificationPort),
kCFRunLoopDefaultMode);
result = IOServiceAddMatchingNotification(terminationNotificationPort,
kIOTerminatedNotification,
matchingDict,
SerialPortWasRemovedFunction,
self, // refCon/contextInfo
&portIterator);
io_object_t d;
// Run out the iterator or notifications won't start (you can also use it to iterate the available devices).
while ((d = IOIteratorNext(iterator))) { IOObjectRelease(d); }
My SerialPortDeviceWasAddedFunction() and SerialPortWasRemovedFunction() are called when a serial port becomes available on the system or is removed, respectively.
Relevant documentation is here, particularly under the heading Getting Notifications of Device Arrival and Departure.
Use IOHIDManager to get the notifications.
Based on the earlier answers from Andrew and Arjuna, I ended up with the following snippet using IOHIDManager that should work with an Apple HID device (e.g. a bluetooth trackpad was tested). This appears to also send notifications more than once without needing to clear/decrement anything.
- (void) startHIDNotification
{
ioHIDManager = IOHIDManagerCreate ( kCFAllocatorDefault, kIOHIDManagerOptionNone );
CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOHIDDeviceKey);
CFDictionaryAddValue(matchingDict, CFSTR(kIOHIDManufacturerKey), CFSTR("Apple"));
IOHIDManagerSetDeviceMatching (ioHIDManager, matchingDict);
IOHIDManagerRegisterDeviceMatchingCallback( ioHIDManager, AppleHIDDeviceWasAddedFunction, (__bridge void *)(self) );
IOHIDManagerRegisterDeviceRemovalCallback( ioHIDManager, AppleHIDDeviceWasRemovedFunction, (__bridge void *)(self) );
hidNotificationRunLoop = CFRunLoopGetCurrent();
IOHIDManagerScheduleWithRunLoop(ioHIDManager,
hidNotificationRunLoop,
kCFRunLoopDefaultMode);
}
and the callback methods
void AppleHIDDeviceWasAddedFunction( void * context,
IOReturn result,
void * sender,
IOHIDDeviceRef device)
{
NSLog(#"added");
}
void AppleHIDDeviceWasRemovedFunction( void * context,
IOReturn result,
void * sender,
IOHIDDeviceRef device)
{
NSLog(#"removed");
}

Resources