Skip to content

Instantly share code, notes, and snippets.

View RodolpheBeloncle's full-sized avatar

Rodolphe Beloncle RodolpheBeloncle

View GitHub Profile
@RodolpheBeloncle
RodolpheBeloncle / traefik_tcp_mqtt_mosquitto_docker_compose.md
Created July 22, 2023 09:23 — forked from gimiki/traefik_tcp_mqtt_mosquitto_docker_compose.md
Traefik Reverse Proxy - Mosquitto MQTT Broker - Docker Container

This gist is to configure a Mosquitto MQTT Broker behind a Traefik reverse-proxy, both in a docker container. Mosquitto will be configuread as a TCP Service.

This is a simple configuration used on the same single server. Probably to be adapted for other cases. Having mosquitto behind a reverse proxy enables you to configure TLS on Traefik (likely you already do that for other applications as well) and to load balance different MQTT instances, but that goes beyond this gist.

As noted in Traefik docs, in the router you must use the rule HostSNI(`*`) when using non-TLS routers like in this example. Ref. https://docs.traefik.io/routing/routers/#rule_1

docker-compose.yml

@RodolpheBeloncle
RodolpheBeloncle / app_mqtt_mysql_completed.js
Created March 13, 2023 08:32 — forked from smching/app_mqtt_mysql_completed.js
Node.js application: Store messages from Mosquitto MQTT broker into SQL Database (completed)
var mqtt = require('mqtt'); //https://www.npmjs.com/package/mqtt
var Topic = '#'; //subscribe to all topics
var Broker_URL = 'mqtt://192.168.1.123';
var Database_URL = '192.168.1.123';
var options = {
clientId: 'MyMQTT',
port: 1883,
//username: 'mqtt_user',
//password: 'mqtt_password',
@RodolpheBeloncle
RodolpheBeloncle / espwroom32-mqtt-logic
Created January 17, 2023 08:28
small logic to connect controller to raspberrypi
#include <WiFi.h>
#include <PubSubClient.h>
const char* ssid = "name of the livebox";
const char* password = "password of livebox";
const char* mqtt_server = "adress IP raspberry";
WiFiClient espClient;
PubSubClient client(espClient);
#include <WiFi.h>
#include <WebServer.h>
/* NB : To upload this code on your controller don't forget to choose the right name controller
*/
// Name of your Internet box
const char *ssid = "wifiBoxName";
@RodolpheBeloncle
RodolpheBeloncle / espwroom32-webserver
Created January 9, 2023 05:44
how to set a webserver in espwroom32 controller in view to interact remotly with a ledlamp
#include <WiFi.h>
#include <WebServer.h>
/* NB : To upload this code on your controller don't forget to choose the right name controller
*/
// Name of your Internet box
const char *ssid = "wifiBoxName";
@RodolpheBeloncle
RodolpheBeloncle / gist:c45e28139e941ff14a7da26e95d4588d
Last active January 27, 2022 06:58
JavaScript TDD 3 - Les différents types de tests
1: === create rectangle class with its own methods (rectangle.js) ===
// Rectangle.js
class Rectangle {
constructor(a, b) {
this.a = a;
this.b = b;
}
isSquare() {
@RodolpheBeloncle
RodolpheBeloncle / gist:a83c0b414db5b1fc7ec3ffab24aaa985
Created January 27, 2022 04:49
JavaScript TDD 2 - Test Runners
// capitalizeFirst.test.js
const assert = require('assert');
const capitalizeFirstLetter = require('../capitalizeFirstLetter');
describe('capitalizeFirstLetter', () => {
it('is a function that accepts one argument', () => {
assert.strictEqual(typeof capitalizeFirstLetter, 'function');
assert.strictEqual(capitalizeFirstLetter.length, 1);
});
it('transforms i am learning TDD correctly', () => {
@RodolpheBeloncle
RodolpheBeloncle / gist:93ef39f154fe998030d902239d09b968
Last active January 25, 2022 07:17
TDD en JavaScript 1 - Introduction
=== capitalizeFirstLetter Test ===
// capitalizeFirstLetter.test.js
import 'assert';
const capitalizeFirstLetter = require('../capitalizeFirstLetter');
describe('capitalizeFirstLetter', () => {
it('is a function that accepts one argument', () => {
assert.strictEqual(typeof capitalizeFirstLetter, 'function');
assert.strictEqual(capitalizeFirst.length, 1);
@RodolpheBeloncle
RodolpheBeloncle / redux quest
Created January 25, 2022 05:18
Redux - Un compteur avec Redux et JavaScript (sans React)
const counterRender = document.getElementById('counter-render');
const incrementButton = document.getElementById('button-increment');
const decrementButton = document.getElementById('button-decrement');
const resetButton = document.getElementById('button-reset');
// ACTIONS
const incrementAction = {
type: 'INCREMENT',
};
@RodolpheBeloncle
RodolpheBeloncle / gist:fcc9fcd48d0674c6f74f1e3d2fee38d4
Created January 3, 2022 18:27
Redux - Connecter React et Redux
==== index.js ====
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import counterReducer from './counterReducer'
import './index.css';
import App from './App';