Tunnel – Example of using MQTT to activate/deactivate relays of a 3G modem from an Android/IO mobile phone

¿Buscas alguna otra cosa?

Scenario details:

  • Intended to be able to activate/deactivate relay outputs from an Android or Iphone mobile phone
  • The SIM card to be used is very affordable and does not have a public IP address, but a private one of the kind 10.x.x.x

Solution: MTX-Tunnel firmware + MTX-Java-IoT

Configuration example (config.txt file) for the indicated scenario:

Configuration Observations
GPRS_apn: movistar.es
GPRS_login: MOVISTAR
GPRS_password: MOVISTAR
GPRS_timeout: 0

MTX_model: 199802407
MTX_mode: none
MTX_PIN: 0000
MTX_ping: 30
MTX_pingIP: 8.8.8.8
MTX_ATLimited: off

FIREWALL_enabled: off
TELNET_enabled: on
TELNET_login: user
TELNET_password: 1234
TELNET_firewall: off
TELNET_port: 20023

MQTT_enabled: on
MQTT_server: tcp://test.mosquitto.org:1883
MQTT_id: [IMEI]
MQTT_attopic1: [IMEI]/AT1
MQTT_qos: 2
MQTT_keepalive: 300
MQTT_persistent: off
GPRS APN provided by GSM operator
GPRS Login
GPRS Password
Modem is permanently connected to GPRS
MTX-Terminal modem model used
We do not configure gateways
PIN if it has one
Every 30 minutes PING check
IP address for connection checking
We do not want limited AT commands
All authorized Ips
We enable the Telnet of the modem
Login for Telnet
Password for Telnet
They can be connected by telnet from any IP
Port for Telnet
We enable the MQTT service on the modem
We specify the broker IP/DNS, including port
Identifier
To receive commands
Quality of service
Keep alive MQTT connection (300 seconds)
We do not need persistence

Testing the example:

To test this example, let’s assume that the modem has already loaded the config.txt file and with the inserted SIM. What we are going to configure here is an example for the phone. Suppose it is an Android phone.

  • We download an MQTT application of the PlayStore. For example MQTT Dash
  • We configure certain details of the application. For example, we created a MTX-TUNNEL device
  • Once the MTX-TUNNEL device has been created, we create and configure a button, for example one with the name RELÉ1.
  • We configure the name of the relay and the topic that we configure in MQTT_attopic1 (obviously replacing [IMEI] tag with the corresponding imei. We configure the command AT ^ MTXTUNNEL= SETIO, X, 0 in the active button, and in the disabled one AT ^ MTXTUNNEL = SETIO, X, 1 (where we will enter X = 0,1,2,6 depending on the relay to be switched). We can specify a QoS 2.
  • Repeating the previous process 4 times (one for each Relay), we can generate an application like the following one