Why does my Arduino fail to connect to my Mosca Broker? - arduino

I am learning MQTT and I deployed the open source mosca broker to an azure web app. The problem is the broker works between 2 pcs but When I try to connect my arduino nano to the broker it always fails. Here is my server code:
//Mosca
const mosca = require('mosca')
const settings = {
http: {
// port for websockets, MQTT is running in default port 1883
port: 8000,
bundle: true,
static: './public'
}
}
// start mosca
const moscaServer = new mosca.Server(settings)
moscaServer.on('ready', setup)
// fired when the mqtt server is ready
function setup() {
console.log('Mosca server is up and running in port 1883!')
console.log('Using port 8000 for MQTT over Web-Sockets!')
}
// fired when a client is connected
moscaServer.on('clientConnected', function(client) {
console.log('client connected', client.id)
})
// fired when a message is received
moscaServer.on('published', function(packet, client) {
//if (packet.topic == '/example') {
console.log(packet.payload.toString('utf-8'))
//}
})
// fired when a client subscribes to a topic
moscaServer.on('subscribed', function(topic, client) {
console.log('subscribed : ', topic)
})
// fired when a client unsubscribes to a topic
moscaServer.on('unsubscribed', function(topic, client) {
console.log('unsubscribed : ', topic)
})
// fired when a client is disconnecting
moscaServer.on('clientDisconnecting', function(client) {
console.log('clientDisconnecting : ', client.id)
})
// fired when a client is disconnected
moscaServer.on('clientDisconnected', function(client) {
console.log('clientDisconnected : ', client.id)
})

From Azure App Service WebApp stand-point - by default, App Service assumes your custom container is listening on port 80. If your container listens to a different port, set the WEBSITES_PORT app setting in your App Service app.
A WebApp can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports.
App Service currently allows your container to expose only one port for HTTP requests.
I’m not much sure about - MQTT broker. Also, how exactly you're attempting to connect.
From App Service- Docker Compose options-Kindly checkout the doc, Supported and Unsupported configuration.
• Only one container can be open for access
• Only port 80 and 8080 is accessible (exposed ports)
Kindly refer this document for more details.
Note: Web Sockets are supported on Linux apps.

Related

How to establish HTTPS/ssl/tls Backend <=> Frontend connection using angular 13?

I have a API-REST service in ASP.NET CORE web-api NET 6. I am using client certificate authentication with the following configuration.
builder.WebHost.ConfigureKestrel(options =>
{
options.ConfigureHttpsDefaults(listenOptions =>
{
listenOptions.ServerCertificate = serverCertificate;
listenOptions.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
listenOptions.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
listenOptions.CheckCertificateRevocation = false;
//listenOptions.AllowAnyClientCertificate();
listenOptions.ClientCertificateValidation = (certificate, chain, errors) =>
{
if (chain.Build(certificate))
//Add certificate verification
return true;
return false;
};
});
options.ListenLocalhost(7120, op =>
{
op.UseHttps(serverCertificate);
op.Protocols = HttpProtocols.Http1AndHttp2;
op.UseConnectionLogging();
});
});
It works perfectly from POSTMAN adding the client certificate issued by my CA and its intermediate certificate.
I get this error in Angular. (ERR_BAD_SSL_CLIENT_AUTH_CERT)
I have the CORS already configured.
How can I send the client's certificate from Angular to the backend or how do I establish communication?
there is no need that your frontend app (spa) knows any thing about tls or domain or IP your server has
you have environment variable
//development
baseUrl:'localhost:5001'
//production
// enviroment.prod.ts
baseUrl:'/api/'
when your in production build for it
simply do not use certificate for developement

MassTransit RabbitMq remote connection

I am having trouble connecting to rabbitMq on remote server to public ip using masstransit. Let's say ip is 000.000.0.00.
While starting an app the next error is shown
RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable
x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(config =>
{
var rabbitMqUri = new Uri("rabbitmq://000.000.0.00");
config.Host(rabbitMqUri, h =>
{
h.Username(configuration["RabbitMQ:UserName"]);
h.Password(configuration["RabbitMq:Password"]);
});
})

Should GRPC net and Azure app service work

In this video for .Net 7 and GRPC
https://www.youtube.com/watch?v=et_2NBk4N4Y
the say that GRPC should work on azure linux app service.
I have implemented following this guide with no success.
https://github.com/Azure/app-service-linux-docs/blob/master/HowTo/gRPC/use_gRPC_with_dotnet.md
this is my program.cs
var builder = WebApplication.CreateBuilder(args);
// Additional configuration is required to successfully run gRPC on macOS.
// For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682
#if Debug
builder.WebHost.ConfigureKestrel(options =>
{
// Setup a HTTP/2 endpoint without TLS.
options.ListenLocalhost(5253, o => o.Protocols =
HttpProtocols.Http2);
});
#endif
#if RELEASE
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(8080);
options.ListenAnyIP(5253, listenOptions =>
{
listenOptions.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http2;
});
});
#endif
// Add services to the container.
builder.Services.AddGrpc();
builder.Services.AddGrpcReflection();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.MapGrpcService<MobileAppsService>();
app.MapGrpcReflectionService();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
app.Run();
Try test with Postman and only get Error: Received RST_STREAM with code 0
all work run local.

Fail to connect to socket.io server on Window Server in dotnet core

I host a very simple node socket IO application on my Window Server, below are the code sample.
// socket.io 3.1.2"
const port = 30080;
const httpServer = require("http").createServer();
const io = require("socket.io")(httpServer, {
cors: {
origin: '*',
methods: ["GET", "POST"],
allowedHeaders: ["Access-Control-Allow-Origin"],
credentials: false
}
});
io.on("connection", socket => {
console.log('On Connection');
io.emit("message", 'Welcome to Socket Io.');
});
And I wrote some code to try connect to my socket IO server in a HTML File and work well. below are the code sample.
// <script src="https://cdn.socket.io/3.1.3/socket.io.min.js"></script>
const socket = io("http://myserverip:30080", {
withCredentials: false,
extraHeaders: {
"Access-Control-Allow-Origin": "*"
}
});
socket.on("connect", () => {
console.log('connect');
});
socket.on("message", (message) => {
console.log(message);
});
But when I try to use those above code in my .NET Core web application, I get the error "ERR_SSL_PROTOCOL_ERROR". Even I publish my web application on the Window Server still getting the same error message.
I have tried http, https, ws and wss protocol. None of these work. How can I get this possibly working?
I do not see the following in your server side code:
httpServer.listen()
Do you have a reverse proxy between your client and the server?
I would expect no SSL related error based on you code.
I would also use socket.io version 4 just for future maintenance reasons.

Transfer UDP socket in node.js from Application to HTTP

Is it possible to transfer a Socket coming from a application to http via NodeJS?
I send my socket with a application (in c++) in UDP or TCP(if impossible in UDP...) to NodeJS.
My script from NodeJS:
var server = dgram.createSocket("udp4");
server.on("message", function (content, rinfo)
{
console.log("socket: " + content + " from " + rinfo.address + ":" + rinfo.port); });
server.on("listening", function () {
});
server.bind(7788);
Up to now does that function, but then how to transfer my socket to Socket.io for example?
I would like to send the socket to Socket.io (for example) for transfer the socket to HTTP. By using a function like this for example, but without renew a establishing a connection to socket.io :
io.sockets.on('connection', function (socket) {
socket.emit(content);
});
Thanks you for your help.
++ Metra.
Here's a complete example with a socket.io server, a web server sending out a very simple page (it will just log all messages to console) and an UDP socket listening for messages, passing them to all connected clients:
var http = require('http'),
dgram = require('dgram'),
socketio = require('socket.io');
var app = http.createServer(handleRequest),
io = socketio.listen(app),
socket = dgram.createSocket('udp4');
socket.on('message', function(content, rinfo) {
console.log('got message', content, 'from', rinfo.address, rinfo.port);
io.sockets.emit('udp message', content.toString());
});
function handleRequest(req, res) {
res.writeHead(200, {'content-type': 'text/html'});
res.end("<!doctype html> \
<html><head> \
<script src='/socket.io/socket.io.js'></script> \
<script> \
var socket = io.connect('localhost', {port: 8000}); \
socket.on('udp message', function(message) { console.log(message) }); \
</script></head></html>");
}
socket.bind(7788);
app.listen(8000);
Update: As io.sockets.emit shows, all messages received on the UDP port 7788 are sent to all connected clients. If you want to route them based on some data in the message or similar, you could use Socket.IO's "room" feature: io.sockets.of(someRoom).emit. In the connection handler for Socket.IO, you can join each client to some room.

Resources