Suchen Sie etwas anderes?
Scenario details:
- It is necessary to control 1 relay to activate the pumping motor of a well
- An analog 0-10V level sensor is available. When the level is low, that is, when the sensor returns a value below 2V, the relay acting on the motor must be activated to pump water. When the sensor returns a value above 8V, the relay must be deactivated to stop pumping water.
- The relay status (on/off) must be sent via 4G/3G/2G to an MQTT broker every time a change occurs. It must also be possible to activate/deactivate the modem relay that controls the well motor at any time from the MQTT broker, that is, remotely. A drop in connectivity with the MQTT broker should not interfere with the behavior of the analog sensor input to the relay
Solution: MTX-Tunnel firmware + MTX-IOT-S [4-N]
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_pin: 0000 MTX_model: 199802407 MTX_mode: none MTX_ping: 30 MTX_pingIP: 8.8.8.8 MTX_numGSMErrors: 180 MTX_TPProtocol: ntp MTX_TPServer: ntp.roa.es MTX_TPServer2: es.pool.ntp.org MTX_TPFormat: unix MQTT_enabled: on MQTT_server: tcp://broker.mqttdashboard.com:1883 MQTT_id: [IMEI] MQTT_login: MQTT_password: MQTT_attopic1: [IMEI]/AT MQTT_atrtopic: [IMEI]/ATR MQTT_persistent: off MQTT_qos: 1 MQTT_keepalive: 60 MQTT_defaultOTopic: /IOCHANGE MQTT_defaultIOQos: 1 ADC_mode0: voltage ADC_config0: at;2000;8000;0;AT ^MTXTUNNEL=SETIO,8,1;AT ^MTXTUNNEL=SETIO,8,0;AT GPIO_mode8: output GPIO_config8: normal |
GPRS APN provided by GSM operator GPRS Login GPRS Password Modem is permanently connected to GPRS PIN if it has one Device model Gateways used Every 30 minutes PING check Google IP (f.e.) to ping Reset if no registry on GSM network in 1800 secs. Time synch protocol Time server Time server backup Unix time format MQTT service MQTT broker, format protocol://url:port Device ID in broker Username Password MTX topic to recieve AT commands Topic where MTX sends responses to AT commands Persistence QoS established Keepalive MQTT topic to inform of output changes in real time MQoS to inform of output changes in real time ADC0 configured as voltage analog input – GPIO8 configured as a mandatory output (relay) GPIO8 configured as a normal output |
Details:
-
The MTX-IOT-S family modems have up to 8 digital outputs (from GPIO0 to GPIO7) and 1 integrated relay (GPIO8). In this example GPIO8, which is associated with the MTX-IOT-S modem relay, has been configured to enable / disable the motor relay
The analog input ADC0 of the MTX-IOT-S modem must be configured to read voltage (do not forget to properly configure the microswitches to configure the ADC0 in voltage mode, you will find more information in the Annexes of this manual)
By configuring the MQTT_defaultIOTopic parameter, the modem will report in that MQTT topic in real time any change in the input / output GPIOs. For this reason, each time the relay associated with GPI8 is activated / deactivated, the modem will send a JSON to said topic MQTT informing of the new status
The sending format of these messages follows the JSON structure, shown in the following example:
{
“IMEI”:”354033091487838”,
“TYPE”:”GPIO”,
“TS”:” 2020-02-09T12:33:18Z”
“ID”:”8”,
“VALUE”:1,
“DIR”:”INPUT”
}Where:
– IMEI: indicates the IMEI of the MTX modem
– TYPE: indicates the type of frame. “GPIO” is for digital I / O frames
– TS: Timestamp (unix format specified in MTX_TPFormat)
– ID: indicates the index of the GPIO (0 = GPIO0, 1 = GPIO1 …, 7 = GPIO7)
– VALUE: indicates the value of the input (0,1)
– DIR: indicates the type of pin (INPUT / OUTPUT)
The configuration of ADC0 input as at;2000;8000;0;AT^MTXTUNNEL=SETIO,8,1; AT^MTXTUNNEL=SETIO,8,0;AT does:
at: sets the analog input to at, which will cause specific AT commands to be executed when the analog value is above or below a certain threshold
2000: minimum value (in mV) to execute low voltage AT commands
8000: maximum value (in mV) to execute the high voltage AT commands
0: hysteresis (in mV). In this example you don’t need
AT ^ MTXTUNNEL = SETIO, 8.1: the AT command that is executed when the analog input value is below 2000 mV (i.e. the AT command that activates the GPIO8 output (the relay) to activate the motor)
AT ^ MTXTUNNEL = SETIO, 8.0: the AT command that is executed when the analog input value is above 8000 mV (that is, the AT command that disables the GPIO8 output (the relay) to stop the motor)
AT: the AT command that is executed when the sensor value is in the normal zone (that is, between 2000mV and 8000mV). In this example it is not used
To remotely change the state of the GPIO8 (the relay), simply send the command AT ^ MTXTUNNEL = SETIO, 8.1 (to activate the relay) and AT ^ MTXTUNNEL = SETIO, 8.0 (to deactivate the relay) from the MQTT platform. ). AT commands must be sent to the TOPIC MQTT configured in the MQTT_attopic1 parameter and the modem will send the responses to the AT commands to the TOPIC MQTT MQTT_atrtopic
Below is an example of sending the command: