Looking for something else?
Tunnel – Example of using MQTT to activate/deactivate relays of a 3G modem from an Android/IO mobile phone
- 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:
|GPRS APN provided by GSM operator
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
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