Category Archives: IOT / Domoticz

Ultrasonic Sensor HC-SR04 + RP2040 (waveshare) Auto screen lock

Point the sensor at yourself when behind your computer.
When you leave your computer for some seconds, it wil automatically lock your screen. (Windows-L keypress)
The RP2040 is configured as HID so it emulates a keyboard.
Just connect via an usb-cable to your machine

Arduino Code

File > Preferences > Additional Board URLS
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

Change USB Stack!

Download and install Adafruit_TinyUSB.zip

#include "Adafruit_TinyUSB.h"
// defines pins numbers
const int trigPin = D4;
const int echoPin = D5;
// defines variables
long duration;
int distance;
int maxcounter;
uint8_t const desc_hid_report[] =
{
  TUD_HID_REPORT_DESC_KEYBOARD()
};

// D0-D3 NOT USED AT THE MOMENT, I'VE GOT IDEAS FOR EXTRA FUNCTIONALLITY!

// USB HID object. For ESP32 these values cannot be changed after this declaration
// desc report, desc len, protocol, interval, use out endpoint
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_KEYBOARD, 2, false);

//------------- Input Pins -------------//
// Array of pins and its keycode.
  uint8_t pins[] = { D0, D1, D2, D3 };


// number of pins
uint8_t pincount = sizeof(pins)/sizeof(pins[0]);

// For keycode definition check out https://github.com/hathach/tinyusb/blob/master/src/class/hid/hid.h
uint8_t hidcode[] = { HID_KEY_0, HID_KEY_1, HID_KEY_2, HID_KEY_3 , HID_KEY_4, HID_KEY_5 };

#if defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(ARDUINO_NRF52840_CIRCUITPLAY) || defined(ARDUINO_FUNHOUSE_ESP32S2)
  bool activeState = true;
#else
  bool activeState = false;
#endif

void setup()
{
  // Setting pins for Ultrasonic Sensor HC-SR04
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  
#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
  // Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
  TinyUSB_Device_Init(0);
#endif

  // Set up output report (on control endpoint) for Capslock indicator
  // Not used .. yet
  usb_hid.setReportCallback(NULL, hid_report_callback);

  usb_hid.begin();

  // overwrite input pin with PIN_BUTTONx
  // NOT USED 
#ifdef PIN_BUTTON1
  pins[0] = PIN_BUTTON1;
#endif

#ifdef PIN_BUTTON2
  pins[1] = PIN_BUTTON2;
#endif

#ifdef PIN_BUTTON3
  pins[2] = PIN_BUTTON3;
#endif

#ifdef PIN_BUTTON4
  pins[3] = PIN_BUTTON4;
#endif

  // Set up pin as input
  for (uint8_t i=0; i<pincount; i++)
  {
    pinMode(pins[i], activeState ? INPUT_PULLDOWN : INPUT_PULLUP);
  }

  // wait until device mounted
  while( !TinyUSBDevice.mounted() ) delay(1);

maxcounter =0;
}

void loop()
{
  
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor - DEBUG
  //Serial.print("Distance: ");
  //Serial.println(distance);

  // Below will wait for more than 100 measurements with a distance of 100
  // Then it will send a WINDOWS-L (lock) keyboard combination 
  if (distance > 100)
  {
    maxcounter +=1; 
  }
  else
  {
    maxcounter = 0;
  }
  if (maxcounter > 100 && maxcounter < 150)
  {
    maxcounter = 200;
       // Send report if there is key pressed
    uint8_t const report_id = 0;


    uint8_t  modifier = KEYBOARD_MODIFIER_LEFTGUI;
          uint8_t keycode[6] = { 0 };
      keycode[0] = HID_KEY_L;


    usb_hid.keyboardReport(report_id, modifier, keycode);
    delay(10);
    // Un-press keys :)
    usb_hid.keyboardRelease(0);
    
  }

  
  // poll gpio once each 2 ms
  delay(20);

  // used to avoid send multiple consecutive zero report for keyboard
  static bool keyPressedPreviously = false;

  uint8_t count=0;
  uint8_t keycode[6] = { 0 };

  // scan normal key and send report
  for(uint8_t i=0; i < pincount; i++)
  {
    if ( activeState == digitalRead(pins[i]) )
    {
      // if pin is active (low), add its hid code to key report
      keycode[count++] = hidcode[i];

      // 6 is max keycode per report
      if (count == 6) break;
    }
  }

  if ( TinyUSBDevice.suspended() && count )
  {
    // Wake up host if we are in suspend mode
    // and REMOTE_WAKEUP feature is enabled by host
    TinyUSBDevice.remoteWakeup();
  }

  // skip if hid is not ready e.g still transferring previous report
  if ( !usb_hid.ready() ) return;

  if ( count )
  {
    // Send report if there is key pressed
    uint8_t const report_id = 0;
    uint8_t const modifier = 0;

    keyPressedPreviously = true;
    usb_hid.keyboardReport(report_id, modifier, keycode);
  }else
  {
    // Send All-zero report to indicate there is no keys pressed
    // Most of the time, it is, though we don't need to send zero report
    // every loop(), only a key is pressed in previous loop()
    if ( keyPressedPreviously )
    {
      keyPressedPreviously = false;
      usb_hid.keyboardRelease(0);
    }
  }
}

// Output report callback for LED indicator such as Caplocks
void hid_report_callback(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
{
  (void) report_id;
  (void) bufsize;

}

Arduino with Huskylens detecting learned face

Arduino Uno with Husky Lens using I2C

The HuskyLens is an easy-to-use AI machine vision sensor. It is equipped with multiple functions such as:

  • Face recognition
  • Object tracking
  • Object recognition
  • Line trace
  • Color recognition
  • Tag recognition (QR code).

Via the UART / I2C port you can among others: boards connect:

  • Arduino
  • micro:bit
  • Raspberry Pi

Steps to take: Press Face detection, when a cross in a square is displayed, press the button on your HuskyLens

Set your husky protocol to I2C in the settings.

Minimal Code needed

/***************************************************
 HUSKYLENS An Easy-to-use AI Machine Vision Sensor
 <https://www.dfrobot.com/product-1922.html> 
****************************************************/

#include "HUSKYLENS.h"

HUSKYLENS huskylens;
//HUSKYLENS green line >> SDA; blue line >> SCL
int ID0 = 0; //not learned results. Grey result on HUSKYLENS screen
int ID1 = 1; //first learned results. colored result on HUSKYLENS screen
int ID2 = 2; //second learned results. colored result on HUSKYLENS screen
// and so on.....

int arjprevious = 0;
void printResult(HUSKYLENSResult result);
void setup() {
    Serial.begin(115200);
    Wire.begin();
    while (!huskylens.begin(Wire))
    {
        Serial.println(F("Begin failed!"));
        Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>I2C)"));
        Serial.println(F("2.Please recheck the connection."));
        delay(100);
    }
    
     huskylens.writeAlgorithm(ALGORITHM_FACE_RECOGNITION);
}

void loop() {
   if (huskylens.requestLearned())          //request blocks and arrows tangged ID != 0 from HUSKYLENS
   if (huskylens.requestBlocksLearned())    //request blocks tangged ID != ID0 from HUSKYLENS

    {
        for (int i = 0; i < huskylens.countArrows(ID0); i++)
        {
            HUSKYLENSResult result = huskylens.getArrow(ID0, i);  
        }
        int arj = huskylens.count(ID1);
        if ( arj != arjprevious )
        {
        if ( arj == 1 )
            {
            Serial.println("Learned face detected");
            }
            else
            {
            Serial.println("Learned face not detected");
            }
            arjprevious = arj;
        }
    }
    else
    {
        Serial.println("Fail to request objects from Huskylens!");
    }
}
Learned face detected ID1
Learned face not detected
Learned face detected ID1
Learned face not detected
Learned face detected ID1
Learned face not detected

Thunderbird mail notification flag via USB

In 2021 I made a MQTT notification Flag using a Servo and python code and webhooks to get notifications.
Webhook was used for Mattermost.

Now i’ve changed the notification flag for Email using Thunderbird.
Just connect the wemos to a USB on your computer, no mqtt/wifi needed. (On the road solution)

Steps:

Install FiltaQuilla Add-on in thunderbird
select run program in config.

Next create a filter

Create two bash files (i’ve got mine in ~/bin/ )
Change ttyUSB0 if needed

::::::::::::::
flagoff.sh
::::::::::::::
#!/bin/bash
stty -F /dev/ttyUSB0 ispeed 9600 ospeed 9600 -ignpar cs8 -cstopb -echo
echo 0 > /dev/ttyUSB0

::::::::::::::
flagon.sh
::::::::::::::
#!/bin/bash
stty -F /dev/ttyUSB0 ispeed 9600 ospeed 9600 -ignpar cs8 -cstopb -echo
echo 1 > /dev/ttyUSB0

Install YAD and a autostart icon to make the systemtray to pull the flag down.

henri@zspot:~$ cat .config/autostart/servoflag.desktop 
[Desktop Entry]
Type=Application
Version=1.0.0
Name=flag-off
Comment=
Icon=
Exec=yad --notification --image="gtk-execute" --command="bash /home/henri/bin/flagoff.sh" --image="mail-app"
Terminal=false

Arduino Code

#include <Servo.h> 

Servo flag; 
char val;
 
void setup() {
  Serial.begin(9600);
  flag.attach(D5);
  }

void loop () {
  val = Serial.read(); 
  if (val == '0') {
     flag.write(180); 
  } 
  if (val == '1') {
     flag.write(0); 
  }
}

I’ve got a Raspberry 5, lets start experimenting

So many things to try .. and probably buy.
I’m lucky to have this already, official it’s not even out yet.

Specification

  • Processor : Broadcom BCM2712 2.4GHz quad-core 64-bit Arm Cortex-A76 CPU, B with cryptography extensions, 512KB per-core L2 caches, and a 2MB shared L3 cache

Features:

  • VideoCore VII GPU, supporting OpenGL ES 3.1, Vulkan 1.2
  • Dual 4Kp60 HDMI® display output with HDR support
  • 4Kp60 HEVC decoder
  • LPDDR4X-4267 SDRAM
    (4GB and 8GB SKUs available at launch)
  • Dual-band 802.11ac Wi-Fi
  • Bluetooth 5.0 / Bluetooth Low Energy (BLE)
  • microSD card slot, with support for high-speed SDR104 mode
  • 2 × USB 3.0 ports, supporting simultaneous 5Gbps operation
  • 2 × USB 2.0 ports
  • Gigabit Ethernet, with PoE+ support
    (requires separate PoE+ HAT)
  • 2 × 4-lane MIPI camera/display transceivers
  • PCIe 2.0 x1 interface for fast peripherals
    (requires separate M.2 HAT or other adapter)
  • 5V/5A DC power via USB-C, with Power Delivery support
  • Raspberry Pi standard 40-pin header
  • Real-time clock (RTC), powered from external battery
  • Power button

Some things come to mind to test:

  • Kubernetes
  • Dual Camera OpenCV – depthmap and more

You really want to use a case with an active blower to cool the rpi.

Measurements without cooling:

  • Power off – part most hot 28 degrees
  • Power on – Idle, around 40 degrees
  • Power on – Playing 4k for 5 minutes – 60+ degrees

Flir info https://www.henriaanstoot.nl/2023/06/05/checking-faulty-chips-hardware/

I didn’t have a image for Raspberry OS 5 at first, so I took a rpi 4 version and first replaced files in /boot
(Device Tree blob files)

Now at least i could boot into an OS.

Later I got a link to the Alpha boot images, this greatly improved usability and speed 🙂

Youtube 4k movie on a 2560×1080 monitor

Made a little overview website:

https://media.henriaanstoot.nl/websites/rpi5/index.html

Flute note detection with leds

Yesterday I got my MAX9814 in, last night I got it working.
Used the leds from a lightpainter project to test controlling the leds.

Why is it, that it doesn’t matter how much components and ledstrips you buy, you alway need more.

First parts of the Scale, then a part of Farewell to Uist

Arduino Nano, using FastLeds library and FFT.
Ledstrip is WS2812, and the MAX8914 microphone

Calibrating temperature/humidity with mqtt

Example uses a shelly sensor, which has a offset mode in its new firmware. So below is not needed any more.
But the example can be used for any calibration/adjustments.

I’ve put two examples in the NodeRed function

First the solution

var temperature=msg.payload.tC;
var humidity=msg.payload.tF;
// calc new offset example
// simple offset + 2.3 off real measurement
msg.payload.tC=temperature + 2.3;
// more complex example
// take two measurements (with a big difference)
msg.payload.tF=1.11 * (humidity - 1);
return msg;

First adjustment is plus or minus a value.
Second is more precise when the temperature needs more adjusting

Dots on the red line are measured values
Blue is how it should be

So measured was 2.8 but should be 2
And measured 14.5 but needs to be 15

slope = (14.5-2.8)/(15-2) = 0.9

To get the multiplication factor = 1/0.9 = 1.1111

=(2.8-heightadjust)*1,1111 should give us 2

2/1.1111 = 2.8 – heightadjust

1.8 = 2.8 – heightadjust = 1

So the formula is realhumid = 1,1111 * ( measuredhumid – adjust )

433mhz sensors and Home Assistant

I’ve got a lot of wifi sensors in my home automation.
But also the ones i’ve started with.
The 433mhz temperature,pir and doorsensors.

These are all connected to Domoticz via a rfxcom gateway.

I’ve previously posted about previous setups.
https://www.henriaanstoot.nl/2022/11/03/home-assistant-and-433-dimmers/
https://www.henriaanstoot.nl/2022/11/17/domoticz-nodered-homeassistant-mqtt/

The setup i’ve ended up with is this:

Under hardware in domoticz install the mqtt broker.
Configure your mqtt server (mine is mosquitto)
Add devices to floorplans to send these to Mosquitto

Now i can see the topics in MQTTExplorer

Install the home assistant websocket palette in NodeRed

Configure the nodes like above

These are some example flows (I’ll put the function code below)

Above are the NAMED entities in Home Assistant

CODE

//Code for NR temperature filtering on domoticz IDX
//A door censor uses nvalue instead of svalue1
//Humidity can be svalue2
//Check the Mqtt payload in MQTTExplorer which to use!
var varidx = msg.payload.idx;
var varnvalue = msg.payload.svalue1;
if(varidx == 3108)
{
msg.payload = {};
msg.payload = varnvalue;
return msg;
}

Example of the trigger node.
When a temperature sensor battery dies, and no new data arrives- in 1 hour, I get a pushover warning. (use pushbullet/email/TV notification whatever you want)

Shelly Dimmer and NodeRed an update ..

Our bedroom has a shelly dimmer, this one is connected with a wall switch and is being controlled by Domoticz, Home Assistant and NodeRed.

I had to fix some stuff, so this was a perfect time to jot down some notes.

I’ve wired it up like this:
(I’ve got a Line wire in my ceiling socket, so i placed the module there instead of the wall socket)

Configure the Shelly as mentioned in the manual. After that do the following:
Advance > Developer settings :
(Enable CoIot if you want a easy auto detect for Home Assistant)
Enable MQTT (This will DISABLE cloud ! )
Server: the ip number of your Mqtt Broker

Next I did was:

Now the wall switch will change/toggle what the current state is.
(If the light is off, and you switch it on using Mqtt, you probably needed to hit the switch two times to turn it off again. Not so with this setting.)

My Nodered Flow ( Not using the Shelly palette nodes in this example)

The Mqtt IN node sets the state of the switch when you use the wall switch!
Cozy turns light on at a specific level.
The slider send an off command when 0% selected, else an on command and the sliders value.

# Cozy function
msg.payload = {};
msg.payload.turn="on";
msg.payload.brightness=30;
return msg;

# Slider function
var varlevel = msg.payload;
msg.payload = {};
if(varlevel == 0){ 
msg.payload.turn="off";
} else
{
    msg.payload.turn="on";
}
msg.payload.brightness=varlevel;
return msg;

DashBoard

The Flow

[
    {
        "id": "32d1c58277d38408",
        "type": "ui_switch",
        "z": "746c372deb597681",
        "name": "",
        "label": "Bedroom lights2",
        "tooltip": "",
        "group": "c387df0cfc06c60e",
        "order": 3,
        "width": 0,
        "height": 0,
        "passthru": false,
        "decouple": "true",
        "topic": "",
        "topicType": "str",
        "style": "",
        "onvalue": "on",
        "onvalueType": "str",
        "onicon": "",
        "oncolor": "",
        "offvalue": "off",
        "offvalueType": "str",
        "officon": "",
        "offcolor": "",
        "animate": true,
        "className": "",
        "x": 220,
        "y": 940,
        "wires": [
            [
                "df432d3faea35f38"
            ]
        ]
    },
    {
        "id": "fb12eddd50d3013e",
        "type": "ui_slider",
        "z": "746c372deb597681",
        "name": "",
        "label": "Bedroom Lights2",
        "tooltip": "",
        "group": "c387df0cfc06c60e",
        "order": 4,
        "width": 0,
        "height": 0,
        "passthru": true,
        "outs": "end",
        "topic": "",
        "topicType": "str",
        "min": 0,
        "max": "100",
        "step": 1,
        "className": "",
        "x": 230,
        "y": 900,
        "wires": [
            [
                "d9c299ec7c0c82b0"
            ]
        ]
    },
    {
        "id": "d9c299ec7c0c82b0",
        "type": "function",
        "z": "746c372deb597681",
        "name": "Get level",
        "func": "var varlevel = msg.payload;\nmsg.payload = {};\n\nif(varlevel == 0){ \nmsg.payload.turn=\"off\";\n} else\n{\n    msg.payload.turn=\"on\";\n}\n\nmsg.payload.brightness=varlevel;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 900,
        "wires": [
            [
                "315ffbe441467c10"
            ]
        ]
    },
    {
        "id": "df432d3faea35f38",
        "type": "mqtt out",
        "z": "746c372deb597681",
        "name": "",
        "topic": "shellies/shellydimmer-CFE204/light/0/command",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "8c74c5f6.9a7a48",
        "x": 800,
        "y": 940,
        "wires": []
    },
    {
        "id": "315ffbe441467c10",
        "type": "mqtt out",
        "z": "746c372deb597681",
        "name": "",
        "topic": "shellies/shellydimmer-CFE204/light/0/set",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "8c74c5f6.9a7a48",
        "x": 780,
        "y": 900,
        "wires": []
    },
    {
        "id": "15f1c904607a0adc",
        "type": "function",
        "z": "746c372deb597681",
        "name": "Cozy",
        "func": "msg.payload = {};\n\nmsg.payload.turn=\"on\";\n\nmsg.payload.brightness=30;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 450,
        "y": 860,
        "wires": [
            [
                "315ffbe441467c10"
            ]
        ]
    },
    {
        "id": "57fb1210d37e5325",
        "type": "ui_button",
        "z": "746c372deb597681",
        "name": "",
        "group": "c387df0cfc06c60e",
        "order": 5,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Bedroom lights2 Cozy",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "",
        "payloadType": "str",
        "topic": "topic",
        "topicType": "msg",
        "x": 240,
        "y": 860,
        "wires": [
            [
                "15f1c904607a0adc"
            ]
        ]
    },
    {
        "id": "30cba96b08f3b830",
        "type": "mqtt in",
        "z": "746c372deb597681",
        "name": "",
        "topic": "shellies/shellydimmer-CFE204/light/0",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "8c74c5f6.9a7a48",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 240,
        "y": 1000,
        "wires": [
            [
                "32d1c58277d38408"
            ]
        ]
    },
    {
        "id": "c387df0cfc06c60e",
        "type": "ui_group",
        "name": "Bedroom",
        "tab": "f177532a78f3f1d2",
        "order": 3,
        "disp": true,
        "width": "6",
        "collapse": true,
        "className": ""
    },
    {
        "id": "8c74c5f6.9a7a48",
        "type": "mqtt-broker",
        "name": "IPBROKER",
        "broker": "IPBROKER",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "15",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "f177532a78f3f1d2",
        "type": "ui_tab",
        "name": "House",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Mikrotik RB4011 Vlan Guest Wifi (IOT) devices

See inline comments:

# Add vlan bridge
/interface bridge
add name=bridge_vlan5

# add security profile for wifi
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
add authentication-types=wpa2-psk eap-methods="" mode=dynamic-keys name=iot supplicant-identity=""

# add virtual wifi to 2.4G and 5G APs
/interface wireless
set [ find default-name=wlan2 ] band=2ghz-g/n country=netherlands disabled=no distance=indoors frequency=auto installation=indoor mode=ap-bridge security-profile=xxxxxxxxxxx ssid=MYSSID station-roaming=enabled wireless-protocol=802.11 wps-mode=\
    disabled
set [ find default-name=wlan1 ] band=5ghz-a/n/ac channel-width=20/40mhz-Ce country=netherlands disabled=no distance=indoors frequency=auto installation=indoor mode=ap-bridge name=wlan5 security-profile=xxxxxxxxxxxxx skip-dfs-channels=all ssid=\
    MYSSID station-roaming=enabled wireless-protocol=802.11 wps-mode=disabled
add disabled=no keepalive-frames=disabled mac-address=4A:8F:5A:48:A4:69 master-interface=wlan2 multicast-buffering=disabled name=wlan_iot2 security-profile=iot ssid=IOT vlan-id=5 vlan-mode=use-tag wds-cost-range=0 wds-default-cost=0 \
    wps-mode=disabled
add disabled=no keepalive-frames=disabled mac-address=4A:8F:5A:80:CE:1D master-interface=wlan5 multicast-buffering=disabled name=wlan_iot5 security-profile=iot ssid=IOT vlan-id=5 vlan-mode=use-tag wds-cost-range=0 wds-default-cost=0 \
    wps-mode=disabled

# Add vlans to virtual Wifi
/interface vlan
add interface=wlan_iot2 name=vlan5_iot-2 vlan-id=5
add interface=wlan_iot5 name=vlan5_iot-5 vlan-id=5

# add ip range for dhcp
/ip pool
add name=dhcp_pool5_iot ranges=10.5.0.2-10.5.0.200

# add dhcp server with above range
/ip dhcp-server
add address-pool=dhcp_pool5_iot interface=bridge_vlan5 name=dhcpiot

# add vlans and interfaces to vlan  bridge
/interface bridge port
add bridge=bridge interface=wlan_iot2
add bridge=bridge interface=wlan_iot5
add bridge=bridge_vlan5 interface=vlan5_iot-5
add bridge=bridge_vlan5 interface=vlan5_iot-2

# add vlan to existing bridge (Not really needed) is for inter vlan traffic
/interface bridge vlan
add bridge=bridge_vlan5 vlan-ids=5

# add interfaces to LAN list (firewall needs this)
/interface list member
add interface=vlan5_iot-2 list=LAN
add interface=bridge_vlan5 list=LAN
add interface=vlan5_iot-5 list=LAN

# Add gateway/dhcpserver ip address
/ip address
add address=10.5.0.254/24 comment="IOT (vlan5)" interface=bridge_vlan5 network=10.5.0.0

# dhcp server network
/ip dhcp-server network
add address=10.5.0.0/24 dns-server=1.1.1.1 gateway=10.5.0.254 netmask=24

# generic NAT rule
/ip firewall nat
add action=masquerade chain=srcnat comment="defconf: masquerade" ipsec-policy=out,none out-interface-list=WAN