Implementing TDMA in UnetStack - communication

I want to simulate a simple TDMA protocol for underwater communication networks, where each node transmits at a regular intervals. How do I implement this in UnetStack?
The UnetStack document on MAC gives examples of Simple and Throttled MAC protocols, but how can I get the nodes to transmit at a regular interval?

A typical agent written using UnetStack can add new behaviors to itself.
In order to transmit at regular intervals as required by a node in TDMA like protocol, your agent can instruct the PHY agent to transmit regularly. This can be implemented using ticker behaviour.
A TickerBehavior runs repeatedly with a specified delay between invocations. A TickerBehavior can be added to your agent with this code:
add new TickerBehavior(1000*slotlength, {
phy << new TxFrameReq(to: nodeAddress, type: Physical.DATA)
})
where slotlength is in seconds and nodeAddress is the address of the node you are trying to transmit the information to. For more information on TxFrameReq you can check out the documentation.

Related

LoRa point-to-point communication

I would like to create a point-to-point connection between a LoRa temperature sensor and a M5 Stack (ESP32) with LoRa module. However, I am a beginner with LoRa, so I have a few questions:
Are all packets send with LoRa (not LoRaWAN) encrypted? Or does it depend on the producer of the LoRa sensor?
Can the content of the packet received by the M5 Stack be viewed? (If I understand correctly, with the LoRaWAN the content can only be viewed after it is on the server).
Can I send measured temperatures from multiple LoRa sensors to one M5 Stack? If yes, how could I distinguish from which sensor the packet has been sent?
Any help would be appreciated!
LoRa means only the RF modulation. All crypto happens in higher layers, i.e. the protocol stack – one possible option for this is LoRaWAN. LoRaWAN uses AES-128 encryption in two layers, Network and Application. You gave no information about the kind of "LoRa temperature sensor" you have, so it is not possible to make a statement about that, other than that it is not LoRaWAN. So this fully depends on the sensor's firmware. There are alternative protocol stacks to LoRaWAN, DASH7 for example. You also might want to have a look at this Stack Overflow article
This too depends on the used protocol stack. With LoRaWAN, you need a gateway to receive the node's LoRa telegrams which are then forwarded to the LoRaWAN cloud (TTN/TTS, for example). Your application can get them from there via Internet. If there's already a TTN gateway in reach, your nodes would automatically use that.
You can actually use the M5 with its WLAN capability to act as a message consumer for multiple nodes by subscribing to the cloud via MQTT, for example – using LoRaWAN. Using LoRa without LoRaWAN, this again depends on the alternative protocol stack you are using here. Of course this requires a working WLAN in reach.
If you are trying to use plain LoRa, which is possible, it is purely your task to implement all the requirements for managing the communication between all involved nodes; it is also your responsibility to ensure that the legal obligations are met.
I would strongly recommend using LoRaWAN and TTN/TTS as it is the de-facto standard for LoRa communications and offers a complete ecosystem that can be used readily without great effort/cost.

How to get a list of all topics containing specific values known to MQTT broker?

I'm looking for a way to get a list of all topics known to a broker. There are some quite similar question's, but they didn't help me to figure it out for my use case.
I've got 3 Raspberry Pi's with multiple sensors (temperature, humidity) which are connected over an MQTT network. Every Pi has it's own database containing time series of measurements and other system variables(like CPU).
Now I'm looking for a way for the following szenario:
I want to monitor my system and detect anomalies. For that I want to get all sensor-time series in the last x seconds and process them in a python script. My system to do the monitoring calculations can be every Pi.
Example: I'm on RPI2 and want to monitor the whole distributed network. There's no given knowledge about the sensors attached to the Pi's. Now from my python script running on RP2 I would initalise a MQTT client and subscribe every sensor data on the broker. I know about the wildcard # but I'm not sure how to use it in that case. My magic command would look like the following pseudo code:
1) client subscribe to all sensor data - #/sensor/#
2) get list with all topics
3) client subscribe to all topics from given list list/#
4) analyse data for anomalies every x seconds
First, your wildcard topic patterns are not valid. Topic patterns can only contain a single '#' character and it can only appear at the end of a topic e.g. foo/bar/# is valid, #/foo is not. You can use the + character which is a single level wildcard character.
This means a topic pattern of +/sensor/# will match each of the following:
rpi1/sensor/foo
rpi1/sensor/bar/temp
but not
rpi1/foo/sensor/bar
Next brokers do not have a list of topics that exist. Topics only really exist at the instant that a message is published to one, the broker then checks the patterns that subscribing clients have requested and checks that topic against the list and delivers it to the clients that match.
Thirdly when bridging brokers in loops like that you have to be very careful with the bridge filters to make sure that messages don' end up a constant loop.
The solution is probably to designate a "master" broker and bridge all the others one way to that broker and then have the client subscribe to either '#' to get everything or something more like '+/sensor/#' to just see the sensor readings.

Which is a good way to send robot states between different ROS nodes?

I am implementing a robotic system based on ROS. I have different nodes which send data multiple times per second. However, I don't need that. I want to send the robot state only when it is at a new location. What technique of ROS do you suggest to use?
Dependent on your requirements, you can either use the ROS Services or the Parameter Server.
ROS Service: The publish / subscribe model is a very flexible
communication paradigm, but its many-to-many one-way transport is not
appropriate for RPC request / reply interactions, which are often
required in a distributed system. Request / reply is done via a
Service, which is defined by a pair of messages: one for the request
and one for the reply.
Parameter Server: A parameter server is a shared, multi-variate dictionary that is accessible via network APIs. Nodes use this server
to store and retrieve parameters at runtime. As it is not designed for
high-performance, it is best used for static, non-binary data such as
configuration parameters.

How to set snmptrap threshold

I want to monitor some firewall devices via SNMP.
So far I've been able to implement retrieval of CPU information using SNMP4J library.
The problem is that I have no idea how to setup and use SNMP traps to get the corresponding warnings and error messages from device asynchronously.
How do I set the CPU threshold so that the SNMP trap will be sent based on that when condition met. For example, if the CPU usage goes above 70%, a trap should be sent to a manager PC. Should I set this threshold on every firewall device by command or implement it using SNMP4J?
I'm confused, please give me some advice on that. Thanks in advance.
Normally, it is the responsibility of the SNMP Agent to send out SNMP traps to notify NMS about certain alarm conditions. But in reality there are many SNMP agents that do not implement it. In this case you'll have to implement this functionality on the SNMP Manager (NMS) side. Basically all you have to do is the following:
Poll the device
Configure threshold values for polling results
Define traps/informs in MIB file
Configure the list of trap destinations
Send out SNMP traps/informs using SNMP4J in full accordance to MIB definition

Wifi mesh-like network using nodeMCU

I have 2 nodeMCU modules, which I want to connect to an MQTT broker and send some data every 5 seconds.
The topology I am trying to achieve is sth like [router]<==[nodeMCU#1]<==[nodeMCU#2]
It looks like [nodeMCU#1] is a wifi extender, but at work we are planning on using multiple nodeMCU's to use in a mesh-like way for an IoT application.
On both of them I flashed the latest (float) release that I downloaded from here https://github.com/nodemcu/nodemcu-firmware/releases/tag/0.9.6-dev_20150704 using nodeMCU-flasher.
For this project wrote 2 lua scripts and I have uploaded them to the modules using ESPlorer.
For the first module it connects in STATIONAP mode to my work wifi, and creates its own network with SSID nodeMCUwifi, with a basic password of 10 characters "1234567890". After it connects the script sends random values to an MQTT topic.
For the second module connects to nodeMCUwifi correctly, it is assigned an IP address, but it cannot connect to the MQTT broker.
When I try to connect to nodeMCUwifi using my smartphone (just to test the connection, I have no intention of using this system for heavy internet load, only MQTT messages) I get a message "authentication error occured" even though I have typed the password correctly, or (in rarer cases)it connects but disconnects immediately.
I would appreciate any ideas to resolve this issue. Thank you.
EDIT: At the AP configuration I added the auth parameter set to 3, I am pasting a part of my code below.
cfg.ssid="ESP8266_"..node.chipid();
cfg.pwd="1234567890"
cfg.auth=3
wifi.ap.config(cfg);
Now my laptop and my smartphone connect to the wifi created by the module, but still have no connectivity to the internet. I can ping the module, but I can't ping 8.8.8.8 or the MQTT broker IP or anything else.
As I understand, [nodeMCU#1] creates a wifi network named nodeMCUwifi. Then the others are trying to connect to nodeMCUwifi. As You stated:
Now my laptop and my smartphone connect to the wifi created by the module, but still have no connectivity to the internet. I can ping the module, but I can't ping 8.8.8.8 or the MQTT broker IP or anything else.
I assume your laptop and smartphone connects to the nodeMCUwifi network. Now you want this [nodeMCU#1] act like layer 2 switch or something like router(since SOFTAP creates its own ip network).
With all this information on hand, I can say that the purpose you are trying to achieve is not possible with esp. Since esp has not enough resources to act like switch or similar. Also (currently) there is no software implemented in esp to achieve that.
However; if only you want the system to transfer certain type of traffic (such as MQTT) over a certain protocol (such as UDP) it is possible to relay the messages like a mesh structure but this will work one-way only. In this configuration the nodes will act more like repeater but on upper layers of OSI. For this idea i cannot provide sample code but I will provide pseudo-code below:
Configuration
> Each node must be configured to build a chain structure. That means each SOFTAP node should have different SSID or TCP settings. For example:
router(192.168.0.0)<----[NODE#1(SOFTAP0)]<----[NODE#2(SOFTAP1)]<---...
...
...
...<----[NODE#n(STATION)]
> Each node must have a TARGET IP address according to setup. This means every node will send the MQTT message to that address.
> If a node is configured as a SOFTAP, this means this system is a TARGET and must listen to a specific port.
> If a SOFTAP node receives some data on the port that is listening to, it should send the data immediately (or buffering) to its TARGET node.
> As a result of this chaining operation the message, no matter what is the source, will reach to the end of the chain.
CODE : SOFTAP
...soft ap config...
listento.port: udp.965
on("receive"):
create.conn:TARGET
send(DATA_RECEIVED)
close.conn:TARGET
CODE : STATION
...station config...
...Do some logic...
data=gather.data()
create.conn:TARGET
send(data)
close.conn:TARGET

Resources