I have a Rpi-A connected to internet via 3G surf-stick and Rpi-B connected to internet via a WiFi hotspot. Rpi-A has a public ip address and also ports 1883 and 8883 are open. Both raspberry Pi's are on different networks. I am attempting to send binary data using MQTT from Rpi-B to Rpi-A.
update: I used the below code to test the MQTT connection. replacing XX.XX.XX.XX with public IP of raspberry Pi. Still I end up getting this error--->
error: [Errno 10060] A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond.
what might be the possible reason for this error ? Is there anything missing in my code
import paho.mqtt.client as mqtt
import time
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client = mqtt.Client()
client.on_connect = on_connect
client.connect("xx.xx.xxx.x", 1883, 60)
client.loop_start()
while True:
time.sleep(2)
client.publish('Due_0.72/cmd/in','hello')
print "publish.."
Related
I am using the docker image of guacamole (oznu/guacamole:amd64). When I try to connect to a RDP host, I get the message "You have been disconnected".
In the configuration, I set the following parameters:
Protocol = RDP
Network/Hostname = ...
Network/Port = 3389
Authentication/Username = ...
Authentication/Password = ...
Authentication/Security mode = any (also tried all the others)
Authentication/Ignore server certificate = Checked
When I look into the logs of the docker container after a failed connection attempt, I see the following error:
17:54:40.256 [http-nio-8080-exec-8] INFO o.a.g.tunnel.TunnelRequestService - User "guacadmin" connected to connection "1".
guacd[533]: INFO: Loading keymap "base"
guacd[533]: INFO: Loading keymap "en-us-qwerty"
guacd[533]: INFO: Connected to RDPDR 1.13 as client 0x0002
*** Error in `guacd': munmap_chunk(): invalid pointer: 0x000055d216529840 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bfb)[0x7f5f2e172bfb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76fc6)[0x7f5f2e178fc6]
/usr/lib/x86_64-linux-gnu/libwinpr2.so.2(Stream_Free+0x2f)[0x7f5f2974577f]
/usr/lib/x86_64-linux-gnu/libfreerdp2.so.2(+0x7840d)[0x7f5f29d2c40d]
/usr/lib/x86_64-linux-gnu/libfreerdp2.so.2(+0x78a25)[0x7f5f29d2ca25]
/usr/lib/x86_64-linux-gnu/libfreerdp2.so.2(freerdp_channels_check_fds+0x35)[0x7f5f29d2d5f5]
/usr/lib/x86_64-linux-gnu/libfreerdp2.so.2(freerdp_check_event_handles+0x48)[0x7f5f29d2b128]
/usr/local/lib/libguac-client-rdp.so(guac_rdp_client_thread+0x287)[0x7f5f2a01e927]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x74a4)[0x7f5f2f6fb4a4]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7f5f2e1ead0f]
======= Memory map: ========
...
The RDP host machine is running Windows 10. I tested it with another machine also running Windows 10.
I also verified:
Other machines can connect to that RDP host using the same hostname, port, username and password as supplied
The host can be pinged from within the docker container
If the credential are not correct I get a different error saying the log in has failed, so the credentials are actually verified by the RDP host
In Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp "UserAuthentication" is 0 and "SecurityLayer" is 1
I expected the RDP connection to work
I am running a local Mosquitto (MQTT) Broker that connects to a remote Mosquitto Broker using the build in MQTT Bridge functionality of Mosquitto. My mosquitto.conf looks like this:
# =================================================================
# Listeners
# =================================================================
listener 1883
# =================================================================
# Security
# =================================================================
allow_anonymous true
# =================================================================
# Bridges
# =================================================================
connection myConnectionName
address <<Remote Broker IP>>:1883
remote_username <<Remote Broker Username>>
remote_password <<Remote Broker Password>>
topic mytopic/# out 1 "" B2/
bridge_protocol_version mqttv50
cleansession false
bridge_attempt_unsubscribe true
upgrade_outgoing_qos true
max_queued_messages 5000
For testing I run a MqttPublisher using a C# console application which uses the MQTTnet library (version 3) and a MqttSubsbriber (also C# console application with MqttNet).
Now I want the Publisher to publish MQTT messages with User Properties (introduced by MQTT 5).
I build the message like this:
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Client.Options;
class Program
{
static void Main()
{
// Create a new MQTT client instance
var factory = new MqttFactory();
var mqttClient = factory.CreateMqttClient();
// Setup the options for the MQTT client
var options = new MqttClientOptionsBuilder()
.WithClientId("MqttPublisher")
.WithTcpServer("localhost", 1883)
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500)
.WithCleanSession()
.Build();
mqttClient.ConnectAsync(options).Wait();
var i = 0;
while (true)
{
Console.WriteLine("Client connected: " + mqttClient.IsConnected);
var message = new MqttApplicationMessageBuilder()
.WithTopic("mytopic/test")
.WithUserProperty("UPTest","Hi UP")
.WithPayload("Hello World: " + i)
.Build();
mqttClient.PublishAsync(message).Wait();
Console.WriteLine("Published message with payload: " + System.Text.Encoding.UTF8.GetString(message.Payload));
i++;
System.Threading.Thread.Sleep(1000);
}
mqttClient.DisconnectAsync().Wait();
}
}
With the subscriber (also with WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500) if I subscribe to the topic I get all the messages and I can read the MQTTnet.MqttApplicationMessage like shown in the following screenshot:
The messages are also published to the remote MQTT Broker due to the MQTT Bride configured. However, if I subscribe to the remote Broker with my MqttSubscriber, I am not getting the User Properties anymore:
Is there any way to configure the Mosquitto Bridge that also the user properties are send? I cant find a way and any help and comments are appreciated.
Thanks
Joshua
Using mosqutto 2.0.15 I have verified that MQTTv5 message properties are passed over the bridge.
Broker one.conf
listener 1883
allow_anonymous true
Broker two.conf
listener 1884
allow_anonymous true
connection one
address 127.0.0.1:1883
topic foo/# both 0
bridge_protocol_version mqttv50
Subscriber connected to Broker two
$ mosquitto_sub -t 'foo/#' -V mqttv5 -p 1884 -F "%t %P %p"
foo/bar foo:bar ben
Publisher connected to Broker one
$ mosquitto_pub -D PUBLISH user-property foo bar -t 'foo/bar' -m ben -p 1883
As you can see the the %P in the output format for the subscriber is outputting the user property foo with a value of bar when subscribed over the bridge.
Setup:
I have 3 docker containers
1) For Kafka
2) For Zookeeper
3) For JupyterLab
I setup networking between these containers and I see that kafka producer is able to run and produce the data.
KafkaProducer.ipynb
KAFKA_BROKER = ['172.20.0.2:9093']
from kafka import KafkaProducer
from kafka.errors import KafkaError
producer = KafkaProducer(bootstrap_servers=KAFKA_BROKER)
for _ in range(100):
print("sending")
producer.send('my-topic', key=b'foo', value=b'bar')
print("success")
Here the send() sends message 100 times.
KafkaConsumer.ipynb
KAFKA_BROKER = ['172.20.0.2:9093']
from kafka import KafkaConsumer
consumer = KafkaConsumer('my-topic',group_id='my-group',bootstrap_servers=KAFKA_BROKER)
print("Comm success")
for message in consumer:
# message value and key are raw bytes -- decode if necessary!
# e.g., for unicode: `message.value.decode('utf-8')`
print ("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,
message.offset, message.key,
message.value))
In the above consumer code the line print("Comm success") never gets gets executed. Based on producer code execution, the network is open and jupyter is able to talk to kafka broker. But, client is not able to connect to the same broker for data consumption. How can I start debugging this?
By default auto.offset.reset value is latest, so set it to earliest with new group.id
consumer = KafkaConsumer('my-topic',group_id='new-group',auto_offset_reset = 'earliest',bootstrap_servers=KAFKA_BROKER)
I am getting the error:
WebSocket connection to 'wss://iot.XXXX.GG:8883/mqtt' failed: Connection closed before receiving a handshake response
When trying to connect to a remote Mosquitto broker over SSL using Javascript Paho library on Windows 10.
What I have already tried is shown in the following listing:
<script type = "text/javascript" language = "javascript">
var mqtt;
var reconnectTimeout = 2000;
var host="iot.XXXX.GG" ;
var port=8883;
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("Connected ");
message = new Paho.MQTT.Message("Hello World");
message.destinationName = "sensor1";
mqtt.send(message);
}
function MQTTconnect() {
console.log("connecting to "+ host +" "+ port);
mqtt = new Paho.MQTT.Client(host,port,"clientjs");
var options = {
useSSL:true,
timeout: 3,
userName:"abc",
password:"qweqwe",
onSuccess: onConnect
};
mqtt.connect(options);
};
</script>
Expected results should be a message saying 'Connected. Actual results are shown at the beginning of this post as the error I get.
By the way, my Mosquitto.conf file is:
allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883 localhost
protocol mqtt
listener 8883
certfile /etc/letsencrypt/live/iot.XXXX.GG/cert.pem
cafile /etc/letsencrypt/live/iot.XXXX.GG/chain.pem
keyfile /etc/letsencrypt/live/iot.XXXX.GG/privkey.pem
# WebSockets - insecure
listener 8083
protocol websockets
#http_dir /home/ΧΧΧΧ/domains/iot.XXXX.GG/public_html
#certfile /etc/letsencrypt/live/iot.XXXX.GG/cert.pem
#cafile /etc/letsencrypt/live/iot.XXXX.GG/chain.pem
#keyfile /etc/letsencrypt/live/iot.XXXX.GG/privkey.pem
The Paho MQTT client can only connect to a broker configured to run MQTT over WebSockets.
The mosquitto.conf file you have provided has 3 listeners defined.
The default native MQTT listener on port 1883 bound only to localhost
A native MQTT over SSL listener on port 8883 using the letsencrypt certificate
A MQTT over WebSockets listener on port 8083 with the certificates commented out.
If you want to connect from the web page using MQTT over WebSockets and SSL you need to uncomment the certificates from the 3rd listener and change the port you are connecting to in the page to 8083 (not 8883)
I can't connect to mqtt broker "hivemq" until the DNS Retry 2 times.
The problem is that Dns retries after the code have been all executed, so I can't publish any message despite it is connected to broker.
I've tried as wheel to set DNS server but it didn't solved anything.
I am using ESPlorer ide on mac.
Thank you for your help, Luca
ssid = "my ssid"
pswd = "my pswd"
wifi.setmode(wifi.STATION)
print("connecting to wifi")
wifi.sta.config(ssid,pswd)
tmr.delay(5000000)
print(wifi.sta.getip())
net.dns.setdnsserver("8.8.8.8", 0)--sets google first dns server--
net.dns.setdnsserver("8.8.8.8") --equal to above
net.dns.setdnsserver("8.8.4.4", 1) --sets google second dns server
--net.dns.setdnsserver("208.67.222.222", 0)--sets opendns first dns server
--net.dns.setdnsserver("208.67.222.222") --equal to
--net.dns.setdnsserver("208.67.220.220", 1) --sets opendns second dns server
--net.dns.getdnsserver(0) --gets first dns server
--net.dns.getdnsserver() --equal to above
--net.dns.getdnsserver(1) --gets second dns server
net.dns.resolve("www.google.com", function (socket,ip)
if ip == nil then print("error: DNS fail!") else print(ip) end
end )
tmr.delay(5000000)
m=mqtt.Client("nodemcu", 1200, "username", "password")
print("hey")
connected = false
m:connect("broker.hivemq.com", function(client) print("connected to broker") connected = true end, function(client,reason) print("reason:") print(reason) end)
tmr.delay(5000000)
if connected==true then print("connected is true") else print("connected is false") end
tmr.delay(10000000)
m:publish("/topic", "hello", 0, function(client) print("message published")end)
This is what I get from nodemcu dev kit 1.0:
192.168.1.64 255.255.255.0 192.168.1.254
hey
connected is false
init.lua:47: not connected
stack traceback:
[C]: in function 'publish'
init.lua:47: in main chunk
[C]: in function 'dofile'
stdin:1: in main chunk
> DNS retry 1!
DNS retry 2!
connected to broker