GPRS-modem Neoway M590 "on wheels". Control of additional heater in the car.

Cheap GSM / GPRS modules studied in detailenthusiasts, including Many alarms, telemetry systems and even an intelligent mailbox have been created. But in all the reviews that I saw, the channel data transfer mode was used - either a phone call or SMS. I will talk about my experience in packet data transmission, and moreover through the UDP protocol under the conditions of severe restrictions on traffic.

It all started when a friend installed a Webasto Thermo Top C inexpensively purchased for the occasion, in the car, along with a circulation pump.
The exchange protocol could not be identified,as well as the model of the car on which it was originally installed. But it was experimentally established that when one of the pins to +12 volts was closed, the heater came to life and began to work.

Immediately the question arose - how to manage it? The first idea on the surface was to adapt a 433 MHz key fob, like this:

What was done. Almost immediately, the shortcomings of this option were revealed:
one. The lack of encryption of radio and the lack of a unique identifier keychain. Of course, hardly anyone will specifically listen to the broadcast to cajole the request to turn on the heater. But in the conditions of the city, if someone next to exactly such a key fob turns on a floor lamp at home, your heater will turn on, which once happened.
2 The circulation pump is powered by the same relay as the start of the heater. The pump stops accordingly, too, at the time of the command to stop the heater, but I would like it to work for a few more minutes.
3 The disadvantage is not directly related to the method of controlling the heater, but requiring a solution: the heater drops out the main battery. See that the engine is warm, but the starter is no longer able to crank it - the pleasure is below average.
four. Finally, the complete absence of any feedback. If the car is parked in direct visibility from the window of the apartment, the fact of passing the switch-on command can still be traced by the appeared pair from the exhaust pipe of the heater. But often the car remains parked out of sight, and there is no certainty that we will come to a warm car. The switch-on command may drown in urban clutter. The team may go, but the heater will not turn on due to problems in the fuel system or due to low battery voltage.
At the end of the first season of operation beganthinking about options for turning on the heater with the possibility of feedback. Research and development work was carried out with the SX1278 radio modules, the results were promising, but with my technological capabilities, the dimensions of the subscriber terminal were not acceptable at all. Carry a key-sized knob the size of a Nokia 3310 solely for the sake of managing a Webasto? It was decided that it was not worth it.
The next idea was to use the mobile network.for control over the internet. It was she who was implemented. The terminal for management was even larger, but it’s still everyone with them - this is a smartphone. In the minuses of the option, you can record the presence of some, albeit small, but the monthly fee, the advantages are the distance, limited only by the coverage of the mobile network and the ability to manage from several places from several devices.
The terms of reference were formulated:
- the heater and the controller will be powered by a separate battery, the benefit of the VW T4 for this is a place under the driver's seat;
- the controller measures three parameters in the car: the temperature of the coolant and the voltage of two batteries;
- the controller establishes a connection with the server via UDP and once every 10 seconds transmits three measured parameters to the server;
- the server returns an acknowledgment of reception, in it the state of the heater relay is transmitted;
- since the voltages of both batteries are known,a free bonus, you can organize the decoupling of batteries: as soon as the voltage on the main battery falls below the set limit, the relay physically disconnects the batteries;
- to control the main actuators requires 3 relays: turn on the heater, turn on the coolant circulating pump, turn on the batteries in parallel;
- the fourth free relyushku on the board will be used for physical shutdown-power-on of the modem, assuming that in terms of restarting it is safer than jerking a special pin;
- you need an Internet server with at least two “white” ports: to communicate with the controller and for the web user interface.
List of components:
1. Arduino Pro Mini - 1 pc.

2. 4-channel relay board - 1 pc.

3. Sensor DS18B20 - 1 pc.

4. Modem M590 - 1 pc.
5. Case, wires, insulating tape, solder, terminals, USB-UART for Arduino programming.
Since there were complaints that the schemes drawnin Fritzing, are a jumble of wires and difficult to read, I divided the circuit into two parts - signal and supply. Wiring diagram to the actuator relay will not be given, since the implementation depends on the type of devices used. It is enough to know that relay No. 1 controls the heater, relay No. 2 controls the circulation pump, relay No. 3 charges the additional battery, and relay No. 4 overloads the modem.
Signal part:

Resistive dividers for voltage measurementbatteries are selected on the basis that the maximum possible battery voltage (say, 15 volts) after dividing does not exceed 1.1 volts - the reference voltage of the internal microcontroller source. I used 1.1 kΩ in the lower shoulder and 15 kΩ in the upper. The coefficient for each specific pair of resistors must be entered in the sketch before loading it (for correct operation of the battery decoupling algorithm) and in the php-script of the user interface (for the correct display of the battery voltage).
The dividers should be placed as close as possible to the Arduin, otherwise the long wires collect interference, and the readings, which are already not very accurate, begin to "jump".

The controller is assembled in a case from the D-Link switch and placed under the driver’s seat next to the auxiliary battery.
The temperature sensor is stretched into the engine compartment and bolted with blue tape to the coolant return pipe to the heater.
Photo taken during installation:

Sketch for Arduino

The modem exchange rate is set to 2400 bps, software UART (SoftSerial library) is used.
The sketch initializes the modem, establishes a connection with the server, then every 10 seconds reads the temperature of the coolant and the voltage of the batteries, then sends them to the server.
Having received a single character response from the serveranswer, analyzes it. If this symbol is a unit, then it turns on the heater and the circulation pump. If this symbol is zero, then the heater is turned off, after 5 minutes the circulation pump is turned off.
If no response from the server is received within 2 minutes, consider that the modem is hanging and pulling its power.
If for 5 seconds the voltage of the mainbattery more than 13.2 volts, closes together the main and additional batteries. If the combined battery voltage is less than 12.8 volts for 5 seconds, disconnects the batteries.
UDP source code

Server side to handle UDP connectionwritten in C and running on VPS running Debian. The server’s duty is to receive a packet, select fragments from it that correspond to the transferred temperature, voltages and relay states, and decompose them into appropriate files. Then take from the file the state of the heater and transfer it to the controller as a single character.
User Interface Source Code

The user interface is written in PHP andis located in the home directory of the web server. The purpose of the script is to pull out “raw” values ​​of temperature, voltages and states from files, bring them to “human readable” form and display them. When you click on the heater start button, put one in the heater status file. When you press the heater stop button, put a zero in the heater status file.
It turned out of course brutal:

But I’m not a hipster, I’m not trained to all kinds of colored buttons and other AJAXs.
In this form, the device has been operated for aboutof the month. No fatal flaws during this time were found. Turns on-off, temperature-voltage shows. Found a useful side effect - in the morning on a cold car, you can find out the actual temperature outside the window directly from the smartphone, not going to the window thermometer.
A little bit about traffic consumption.
Every 10 seconds a request is sent and receivedanswer. The request has 28 bytes header and 7 bytes of payload. The response is 28 bytes header and 2 bytes of payload. Total 65 bytes every 10 seconds. 390 bytes per minute, 561,600 bytes per day, 17,409,600 bytes in 31 days. The calculations almost coincide with the data of the operator:

At the time of this writing, for an incomplete 13 days of the month, 5.5 megabytes of the 50 included in the subscription fee (MTS Belarus “Easy to say” tariff) were spent with a theoretically possible 7 Mb.

I am writing off the difference for finding a car outside the cellular coverage area.
Possible improvements and improvements.
Without much effort, the controller can be supplementedGPS module for tracking the movement. You can use additional relays to control automotive equipment - flashing turn signals, turn on the stove fan, etc. - who has what needs and imagination.
To further save traffic, you can try to implement the KeepAlive mechanism — send packets every few minutes only to monitor the connection status.
Finally, you can open the native heater control protocol and take temperature data via K-Line / CAN directly from the built-in sensor, getting rid of the crutch as an external DS18B20.