216 lines
8.7 KiB
Markdown
216 lines
8.7 KiB
Markdown
# Modbus Reading and GSM/GPS Data Logging for Schneider PowerLogic PM8000 using SIM808 Breakout - GSM & GPS, BAT Input
|
|
|
|
This is a specification and implementation of an Arduino-based Modbus data logger with GSM data transmission and GPS location tracking for the Schneider PowerLogic PM8000. This software is designed for Vivarox EMS and only Vivarox has the right to use and modify this software.
|
|
|
|
## Arduino Implementation:
|
|
|
|
This project uses an Arduino to connect to Modbus devices, read information, transmit it via GSM to a remote server, and provide GPS location data.
|
|
|
|
### Hardware needed:
|
|
|
|
1. Arduino Board
|
|
Recommended: Arduino MEGA 2560 (for more memory and I/O pins) or Arduino UNO (for simpler projects).
|
|
|
|
2. RS485 to TTL Module
|
|
Allows communication between the Arduino and Modbus devices using the RS485 protocol.
|
|
|
|
3. SIM808 Breakout - GSM & GPS, BAT Input
|
|
Enables the Arduino to send data over cellular networks and provide GPS location data.
|
|
|
|
4. Power Supply
|
|
To power the Arduino and connected peripherals. The SIM808 module requires a dedicated power supply capable of providing up to 2A current.
|
|
|
|
5. LED Indicators
|
|
Two LEDs for status indication.
|
|
|
|
6. Capacitors
|
|
100uF and 10uF capacitors for power supply stabilization.
|
|
|
|
7. GPS Antenna
|
|
For receiving GPS signals.
|
|
|
|
### Wiring
|
|
|
|
#### Wiring Diagram
|
|
```
|
|
Arduino Mega/Uno SIM808 Breakout Description
|
|
----------------- --------------- -----------
|
|
5V ----> VCC Power supply (via 2A dedicated supply)
|
|
GND ----> GND Ground
|
|
2 (RX) <---- TX SIM808 TX to Arduino RX
|
|
3 (TX) ----> RX Arduino TX to SIM808 RX
|
|
|
|
7 ----> DI (RS485) RS485 Driver Input
|
|
8 <---- RO (RS485) RS485 Receiver Output
|
|
4 ----> DE/RE (RS485) RS485 Driver Enable/Receiver Enable
|
|
|
|
3 ----> LED A Status LED A
|
|
5 ----> LED B Status LED B
|
|
|
|
Power Supply
|
|
------------
|
|
VCC ----> + (2A) Dedicated 2A power supply positive
|
|
GND ----> - (GND) Dedicated 2A power supply ground
|
|
|
|
Capacitors
|
|
----------
|
|
VCC ----|(---- GND 100uF capacitor
|
|
VCC ---||---- GND 10uF capacitor
|
|
|
|
GPS Antenna
|
|
|
|
|
|
|
|
[SIM808 Breakout Module]
|
|
```
|
|
|
|
#### Wiring Notes:
|
|
1. Ensure the power supply can provide 2A current.
|
|
2. Place the 100uF and 10uF capacitors as close to the SIM808 module's power pins as possible.
|
|
3. The RS485 connections are optional and depend on your specific requirements.
|
|
4. LEDs should be connected with appropriate current-limiting resistors (not shown in diagram).
|
|
5. The SIM808 module's GPS antenna should be connected securely.
|
|
6. Double-check all connections before powering on the system.
|
|
|
|
### Software
|
|
|
|
- Modbus Library: ModbusMaster
|
|
- GSM/GPS Library: TinyGSM (recommended for SIM808)
|
|
- NeoSWSerial: For better latency on software serial communication with Modbus
|
|
|
|
### Implementation Details
|
|
|
|
1. Modbus Configuration:
|
|
- Slave ID: 101
|
|
- Baud Rate: 9600
|
|
- Register map: Defined in separate "register_map_pm8000.h" file
|
|
|
|
2. Data Logging and Transmission:
|
|
- Frequency: Readings taken and transmitted every minute
|
|
- Data Format: CSV (Comma-Separated Values) string
|
|
- Data Structure: Timestamp, GPS coordinates, followed by register values
|
|
- Header Row: Includes register addresses for easy identification
|
|
|
|
3. Register Types Supported:
|
|
- Float (32-bit)
|
|
- Integer (32-bit)
|
|
- String (up to 20 characters)
|
|
|
|
4. Error Handling and Status Indication:
|
|
- LED A: Indicates successful data transmission
|
|
- LED B: Indicates errors (e.g., GSM issues, Modbus communication errors)
|
|
- Serial output for debugging (9600 baud)
|
|
|
|
5. GPS Functionality:
|
|
- Provides real-time location data
|
|
- Supports various NMEA sentences (GGA, GSA, GSV, RMC)
|
|
- Can be used for geofencing applications
|
|
|
|
6. Special Features:
|
|
- Robust error handling for GSM/GPS and Modbus communication
|
|
- Header sent once at the beginning of each session
|
|
- Configurable APN and server URL
|
|
- GPS power saving mode available
|
|
|
|
### Programming Workflow
|
|
|
|
1. Initialize hardware (SIM808 module, RS485 module)
|
|
2. Set up Modbus communication parameters
|
|
3. Configure GSM and GPS settings
|
|
4. Enter main loop:
|
|
- Read data from Modbus registers
|
|
- Obtain GPS location
|
|
- Format data into CSV string including GPS coordinates
|
|
- Send data via GSM to server
|
|
- Handle any errors and provide status indication via LEDs
|
|
- Delay for 1 minute before next reading and transmission
|
|
|
|
## Memory Limitations and Register Customization
|
|
|
|
### Memory Constraints
|
|
|
|
The Arduino, particularly models like the UNO and MEGA, has limited memory available for storing program code and variables. This limitation affects the number of Modbus registers that can be defined and read in a single project.
|
|
|
|
- Arduino UNO: 32 KB Flash (program storage), 2 KB SRAM
|
|
- Arduino MEGA: 256 KB Flash, 8 KB SRAM
|
|
|
|
Due to these constraints, the number of registers that can be defined in the `register_map_pm8000.h` file is not unlimited. The exact number will depend on the complexity of your code and other libraries used.
|
|
|
|
### Customizing the Register Map
|
|
|
|
To adapt this project to your specific needs, you can modify the `register_map_pm8000.h` file. This file contains the definitions of Modbus registers to be read by the Arduino.
|
|
|
|
To customize the register map:
|
|
|
|
1. Open the `register_map_pm8000.h` file in your Arduino IDE or text editor.
|
|
|
|
2. Locate the `registers` array in the file. It should look something like this:
|
|
|
|
```cpp
|
|
const RegisterInfo registers[] PROGMEM = {
|
|
{40001, 2}, // Example register
|
|
{40003, 1},
|
|
// ... other registers ...
|
|
};
|
|
```
|
|
|
|
3. To remove a register, simply comment out its line by adding `//` at the beginning:
|
|
|
|
```cpp
|
|
const RegisterInfo registers[] PROGMEM = {
|
|
{40001, 2}, // Example register
|
|
// {40003, 1}, // This register is now commented out and won't be read
|
|
// ... other registers ...
|
|
};
|
|
```
|
|
|
|
4. To add a new register, add a new line to the array with the register address and type:
|
|
|
|
```cpp
|
|
const RegisterInfo registers[] PROGMEM = {
|
|
{40001, 2}, // Example register
|
|
{40003, 1},
|
|
{40005, 2}, // New register added
|
|
// ... other registers ...
|
|
};
|
|
```
|
|
|
|
5. Remember to keep the array syntax correct, with commas between entries and a semicolon at the end of the array.
|
|
|
|
## Best Practices
|
|
|
|
- Start by commenting out registers you don't need before adding new ones.
|
|
- If you're using an Arduino UNO, you may need to be more selective about which registers to include due to memory constraints.
|
|
- Test your modifications incrementally to ensure the Arduino can handle the memory load.
|
|
- If you need to read a large number of registers, consider using an Arduino MEGA or a more powerful microcontroller.
|
|
- Ensure your GSM data plan can handle the amount of data being transmitted.
|
|
- Regularly check your server to ensure data is being received correctly.
|
|
- Position the GPS antenna with a clear view of the sky for best performance.
|
|
|
|
## Important AT Commands for SIM808
|
|
|
|
Here are some important AT commands used in this project:
|
|
|
|
1. `AT+CGNSPWR=1`: Turn on GNSS power supply.
|
|
2. `AT+CGNSSEQ="RMC"`: Set the last NMEA sentence to RMC (Recommended Minimum Specific GNSS Data).
|
|
3. `AT+CGNSINF`: Get GNSS navigation information.
|
|
4. `AT+CGNSURC=2`: Set URC reporting every 2 GNSS fixes.
|
|
5. `AT+CGDCONT=1,"IP","APN_NAME"`: Set the APN for your cellular provider.
|
|
6. `AT+HTTPINIT`: Initialize HTTP service.
|
|
7. `AT+HTTPSSL=1`: Enable SSL for HTTPS connections (if required).
|
|
8. `AT+HTTPPARA="URL","http://your-server-url.com/upload"`: Set the server URL.
|
|
9. `AT+HTTPDATA=<size>,10000`: Prepare to send HTTP POST data.
|
|
10. `AT+HTTPACTION=1`: Send HTTP POST request.
|
|
|
|
Remember to replace "APN_NAME" and "http://your-server-url.com/upload" with your specific values.
|
|
|
|
## Troubleshooting
|
|
|
|
1. If you encounter communication issues, double-check your wiring and ensure all connections are secure.
|
|
2. Verify that your APN settings are correct for your cellular provider.
|
|
3. If the module isn't responding, try resetting it and check your power supply.
|
|
4. Use AT commands like `AT+CSQ` to check signal strength and `AT+CREG?` to check network registration status.
|
|
5. If GPS data isn't being received, ensure the GPS antenna has a clear view of the sky.
|
|
6. If data isn't being sent, verify your TCP connection settings and ensure you have an active data plan.
|
|
7. Use `AT+CGNSINF` to check GPS fix status and information.
|
|
|
|
By carefully managing the registers in the `register_map_pm8000.h` file and configuring your SIM808 settings, you can customize this Modbus reader to suit your specific requirements while staying within the memory limitations of your Arduino board and optimizing data transmission and GPS functionality. |