Skip to content

SMSServiceWithoutSmartthings

vzakharchenko edited this page Mar 15, 2021 · 1 revision

Mikrotik SMS Service without Smartthings

Hardware Requirements

Mikrotik Configuration

/interface lte
set [ find ] name=lte1
/interface bridge
add dhcp-snooping=yes fast-forward=no igmp-snooping=yes name=bridge2

/interface wireless security-profiles
add authentication-types=wpa-psk,wpa2-psk eap-methods="" \
    management-protection=allowed mode=dynamic-keys name=CarWiFi \
    supplicant-identity="" wpa-pre-shared-key=WIFI_PASSWORD \
    wpa2-pre-shared-key=WIFI_PASSWORD
add authentication-types=wpa-psk,wpa2-psk eap-methods="" \
    management-protection=allowed mode=dynamic-keys name=Mitsubishi \
    supplicant-identity="" wpa-pre-shared-key="MITSUBISHI_PASSWORD" \
    wpa2-pre-shared-key="MITSUBISHI_PASSWORD"
/interface wireless
set [ find default-name=wlan1 ] band=2ghz-b/g/n country=canada disabled=no \
    frequency=2422 mode=ap-bridge name=\
    WiFi_Router security-profile=CarWiFi ssid=CarWiFI wireless-protocol=\
    802.11
add disabled=no mac-address=<PHONE_MAC_ADDRESS> master-interface=WiFi_Router \
    mode=station-pseudobridge-clone name=MitsubihiWiFI security-profile=\
    Mitsubishi ssid=REMOTE_WIFI station-bridge-clone-mac=PHONE_MAC_ADDRESS \
    wds-default-bridge=bridge
/ppp profile


/user group
add name=none
/interface bridge port
add bridge=bridge2 interface=MitsubihiWiFI trusted=yes
/ip dhcp-client
add add-default-route=no disabled=no interface=bridge2 use-peer-dns=no \
    use-peer-ntp=no
/ip dns
set servers=8.8.8.8
/ip firewall filter remove [/ip firewall filter find dynamic=no]
/ip firewall filter

add action=accept chain=input comment="defconf: accept established,related,untracked" connection-state=established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment="defconf: accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
add action=accept chain=input dst-port=22 protocol=tcp
add action=accept chain=input in-interface=all-ppp
add action=accept chain=forward dst-address=192.168.8.0/24
add action=accept chain=forward dst-address=192.168.0.0/24
add action=drop chain=input comment="defconf: drop all not coming from LAN" in-interface-list=WAN
add action=accept chain=forward comment="defconf: accept in ipsec policy" ipsec-policy=in,ipsec
add action=accept chain=forward comment="defconf: accept out ipsec policy" ipsec-policy=out,ipsec
add action=accept chain=forward comment="defconf: accept established,related, untracked" connection-state=established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" connection-state=invalid
add action=drop chain=forward comment="defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat connection-state=new in-interface-list=WAN

/ip firewall nat
add action=masquerade chain=srcnat out-interface-list=WAN
add action=masquerade chain=srcnat out-interface=bridge2
add action=masquerade chain=srcnat out-interface=all-ppp
add action=accept chain=srcnat src-address=192.168.8.0/24
add action=accept chain=srcnat dst-address=192.168.8.0/24
/ip route
add disabled=yes distance=1 dst-address=192.168.8.0/24 gateway=bridge2
/system console
set [ find ] disabled=yes
/system identity
set name=CarWiFi
/system leds settings
set all-leds-off=after-1h
/system scheduler
add interval=3m name=carConnectionSchedule on-event=\
    "/system script run carConnectionCheck" policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-date=sep/14/2020 start-time=10:37:49
add interval=3m name=LTE_Schedule on-event="/system script run check_lte" \
    policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-date=sep/27/2020 start-time=05:47:22
add interval=3m name=CarWifiConection on-event=\
    "/system script run CarWifiConection" policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-date=sep/14/2020 start-time=10:37:49
/system script
add dont-require-permissions=no name=carConnectionCheck owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
    \n:local HOST \"192.168.8.46\"\
    \n:local PINGCOUNT 3\
    \n:local INT \"bridge2\" \
    \n:if ([/ping address=\$HOST interface=\$INT count=\$PINGCOUNT]=0) do={\
    \n:global name=\"tunnel_car\" 0\
    \n/log error \"\$INT is down\"\
    \n\
    \n/interface wireless disable MitsubihiWiFI\
    \n# /log error \"MitsubihiWiFI DISABLED\"\
    \n/delay delay-time=6\
    \n/interface wireless enable MitsubihiWiFI\
    \n# /log error \"MitsubihiWiFI ENABLED\"\
    \n# /delay delay-time=15\
    \n} else={\
    \n:global name=\"tunnel_car\" 1\
    \n}\
    \n"
add dont-require-permissions=no name=check_lte owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
    \n:local HOST \"8.8.8.8\"\
    \n:local PINGCOUNT 3\
    \n:local INT \"lte1\" \
    \n:global counter;\
    \n\
    \n:if ([/ping address=\$HOST interface=\$INT count=\$PINGCOUNT]=0) do={\
    \n:set counter (\$counter+1);\
    \n:if (\$counter >3) do={\
    \n :global name=\"lte_check\" 0\
    \n /log error \"\$INT is down\"\
    \n}\
    \n} else={\
    \n:global name=\"lte_check\" 1\
    \n:global name=\"counter\" 0\
    \n# /log info \"\$INT is up\"\
    \n}\
    \n\
    \n"
add dont-require-permissions=no name=CarWifiConection owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
    \n:local WiFIConnection\r\
    \n/interface wireless monitor MitsubihiWiFI once do={\r\
    \n  :set WiFIConnection \$status\r\
    \n  }\r\
    \n\r\
    \n:if (\$WiFIConnection != \"connected-to-ess\") do={\r\
    \n\r\
    \n   /log error \"MitsubihiWiFI DISCONNECTED\"\r\
    \n   :global name=\"CarConnected\" 0\r\
    \n} else {\r\
    \n   :global name=\"CarConnected\" 1\r\
    \n}"
/tool mac-server
set allowed-interface-list=LAN
/tool mac-server mac-winbox
set allowed-interface-list=LAN
/tool sms
set port=lte1 receive-enabled=yes

Where:

  • PHONE_MAC_ADDRESS - Registered device macaddress
  • REMOTE_WIFI - EV-REMOTE WiFi SSID
  • MITSUBISHI_PASSWORD - EV-REMOTE Password
  • WIFI_PASSWORD - Password for WiFi with internet access

Raspberry Pi

  country=US
  ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
  update_config=1

  network={
      ssid="CarWiFI"
      psk="WIFI_PASSWORD"
  }

where WIFI_PASSWORD - Password for WiFi with internet access

  • open mikrotik admin console: http://192.168.8.1

  • set for your raspberry pi static IP address

  • install phevctl

apt-get upgrade -y && apt-get -y install build-essential cmake git
mkdir /opt/phevctl
cd /opt/phevctl && git clone https://github.com/papawattu/msg-core
cd /opt/phevctl &&  git clone https://github.com/vzakharchenko/phevcore.git
cd /opt/phevctl && git clone https://github.com/DaveGamble/cJSON.git
cd /opt/phevctl && git clone https://github.com/vzakharchenko/phevctl
cd /opt/phevctl/cJSON && mkdir build && cd build && cmake .. && make && make install
cd /opt/phevctl/msg-core && mkdir build && cd build && cmake .. && make && make install
cd /opt/phevctl/phevcore && mkdir build && cd build && cmake .. && make && make install
cd /opt/phevctl/phevctl && mkdir -p build && cd build && cmake .. && make
rm -f /usr/bin/phevctl
wget -qO- https://getpm2.com/install.sh | bash
env PATH=$PATH:/usr/bin pm2 startup systemd -u ${currentUser} --hp ${HOME}
npm i smartthings-phevctl -g
pm2 start `npm root -g`/smartthings-phevctl/smartthings-phevctl.js
pm2 save
  • install node
sudo su
wget https://nodejs.org/download/release/v11.15.0/node-v11.15.0-linux-armv6l.tar.gz
tar -xzf node-v11.15.0-linux-armv6l.tar.gz
cd node-v11.15.0-linux-armv6l/
sudo cp -R * /usr/local/
  • install pm2
sudo su
npm i pm2 -g
env PATH=$PATH:/usr/bin pm2 startup systemd -u ${currentUser} --hp ${HOME}
pm2 startup -u root
pm2 save
  • install application
npm i smartthings-phevctl -g
pm2 start `npm root -g`/smartthings-phevctl/smartthings-phevctl.js
pm2 save
  • open http://:8080
  • enable SMS and SMS Notification
  • Generate mikrotik script for your application and your mobile number
  • open mikrotik admin console: http://192.168.8.1
  • add a new mikrotik script (name should be remote-remote-gsm)
  • add scheduler job and run it every minute