How can I combine RPL, UDP and MQTT in Cooja of Contiki-NG? - mqtt

All this is done in the Cooja simulation.
I need to develop a project in which I have a mote (or many) that acts like a sensor and sends data to a server which does computations and publishes the results on a topic using MQTT.
In both cases I assign IPs to motes using the rpl-border-router example provided by Contiki-NG.
I can publish fake data created by the server and publish it through the border router via MQTT; I can create a tree to send the values from the sensor motes to the server using UDP and compute what The problem is that I can't connect the two.
I don't attach the code because I want to understand the structure that I should use to accomplish this and the general idea behind the solution you propose, if possible
I tried two configurations but none works, because I think I don't have the right structure.
These are the two settings:
one mote per functionality: 1 sensor (1) sending data via UDP to a server (2), this server is set as root using NETSTACK_ROUTING.root_start(), which should publish data through MQTT via the rpl-border-router (3). I think the error here is that the server is set as root, while the rpl-border-router should, but then how can I send data to the server for computations?
use the rpl-border-router (1) as server also, so it computes the outcomes and publishes through MQTT, receiving the values via UDP from sensor mote (2). The problem here is the synchronization between MQTT broker assignment and IPv6 assignments, since both require IP
Thank you

Related

How to solve modbus error on solar inverter?

I am currently working with one of Growatt inverters, 5 KVA residential inverter, It has two ports one is RS-485 I have connected a Smart Energy Meter with it to control backpower flowing to grid, and on the other port Growatt wifi device was working, I wanted to use my own platform, I used this protocol Growatt PV Inverter Modbus RS-485 RTU Protocol and then connected wire to RS-232 with a Raspberry Pi to read the data and send it back to my server. Now the issue coming is as soon as both devices start to work then inverter starts showing an error. I cannot understand why it was not giving with the Growatt device. Is there any solution?
I want to ask some question about your problem to help you if I can :-).
Are you going to monitor inverter data on your server? If yes => so, why you don't connect your server to inverter directly (I mean by using USB to the RS-485 converter).
What is your connection type? If it is Modbus-RTU you need to find Modbus register map to get your desired data. You could find this in the inverter user manual.
Be careful about your Modbus communication configurations and settings (i.e. Baudrate, ID, Parity and Byte Size).

Sending MQTT messages to Orion Context broker

I have a relatively simple switch that sends data whenever the button is pressed (either 1 or 0). The message protocol it uses is MQTT. It is connected to Mosquitto via Wi-Fi and successfully sends data to it (i am able to see it using mosquitto_sub -v -t "#". However, I would like to be able to send this data to Orion Context Broker and then receive it using REST commands and store it using Fiware-Cygnus afterwards.
the topic that sensor publishes messages to is tt/sergo/demo/sw
the name of the sensor presented in mosquitto_sub when sensor is first connected: DMS-A01
the IP - address of sensor: 192.168.0.108
I have installed Iot-Agent UL, which is working, but I don't know how to make it listen to the specific sensor that sends data to Mosquitto.
I read the manuals but either missed something or did not find the solution to my problem.
I tried using the manual below, but could not apply it to my problem.
Connecting "thing" to Fiware
Thank you in advance, stack overflow community.
Before sending measures you need to do a provision operation for the device using the IOTA-UL API. That provision operation "creates" the device in the IOTA-UL and map it with the corresponding entity at CB. Then, you can start sending measures using MQTT.
You can have a look to this piece of documentation for more detail.

PLC cooperate with Modbus Gateway failed

Background:
The plan tries to use Modbus gateway to enable multiple masters to communicate with multiple slaves.The gateway would package Modbus RTU data as TCP/IP data.
Like the image shows below.
The network has two gateway, one work as TCP Client another work as TCP Server.
Every Modbus master uses a different serial port on the gateway, and it would use different TCP port to connect the same TCP server(gateway).
Problem:
One PLC can read through the gateway to get slaves data correctly, while HMI keeps alerting the communication error. They use different serial ports from the gateway.
What I tried:
When using a software to simulate a Modbus master, it can read the data.
And when the HMI connect directly with Modbus slaves, they can communicate.
The serial settings are same, on every device.
When using software simulating, also used Wireshark to diagnose the network. Most frames are [TCP ACKed unseen segment], some say it's what could be ignored. The Modbus data in these frames are correct like shown above.
Totally have no clue now, any suggestion would be appreciated.

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

TCP Listener in Delphi

I want to implement a demo application to listen data via TCP/IP.
Data Transmitter will transmit a series or ASCII char or a series of string all the time. It feeds data into TCP/IP address (eg. 127.0.0.1:22) This could be a GPS transmitter.
I want to implement a demo application for receiving data by clicking the start button and listening to the data via TCP/IP and display it accordingly.
Correct me if I am wrong, I don't think I can use Server/Client server for this purpose. I tried to create a client application with TIdTcpClient, it receives only one time data. I don't think Indy has a TCP listening component.
Thanks in advance.
If you wanna monitor network comunications between some device and some other program on your computer using of TIdTCPServer won't work. Why? Once Indy will read network data it will mark it as processed and delete it from network buffer. So that data probably won't even reach to the other program on your computer. Workaround for this is that you design your application to actually work similar as network bridge. Your application listens to the data on one port and then forwards that data on another port on which the other program is listening. But the main problem is that you have to make this to work both ways.
What you need is somekind of a component which is able to peek at the network data but don't interact with it. This is usually done on driver level.
Now if it is not abolutely necessary to have such functionality in your own software but you are only interested in getting the data I recomend you try Wireshark (http://www.wireshark.org/). Wireshark is a verry powerfull freware software which alows you to monitor all netwrok traffic on basically all protocols without causing any interuptions. In order for this software to work it instals special driver which serves for intercepting the network data.
Maybe you would want to use same driver in your application if this functionality needs to be in your application.
Based on your diagram I think that your implementation could also be based on a message-oriented middleware, using a message broker which receives the GPS transmitter or other data.
The message broker would then store the data internally and forward it to all interested clients which are connected. A typical messaging pattern in this case is a "Topic", which broadcasts the messages similar to a radio station.
So the middleware will ensure that the information will be collected (optionally also persisted to disk) and then guarantees the delivery to the receivers. This can be done even in a way where receivers which have been off-line for a while still receive the GPS messages created while they where not listening ('retroactive consumers').
There are many popular free open source message brokers, and most of them also can be used with Delphi.

Resources