Introduction: Data Transmission of Non-internet Connected Solar Systems With Arduino, PHP and MySQL

Picture of Data Transmission of Non-internet Connected Solar Systems With Arduino, PHP and MySQL

Description

The aim of this arduino project is to acquire and transfer data via the GSM network. The benefit is to be able to collect data (for example monitoring of a solar plant) even if there is no hard wired internet connection available.

This is how it works:

  1. A value is read from arduinos analogue input A0 (in this case temperature)
  2. The GSM modem is started and a is connection established.
  3. pass.php gets called and the data value and security key is passed to the script.
  4. The script saves the value, the IP address and the current server time in the database.
  5. Arduino waits for a specified interval before repeating.
  6. The data can be plotted in a graph with plot.php or written to a csv file with csv.php

The code was inspired by and contains snippets from:

Arduino Daten-logger (MySQL/PHP) by Poldi

GSM Web Client by Tom Igoe

How to stop gsm.begin() by Anders Hedberg

Material

Hardware

  • Arduino (Leonardo)
  • GSM Shield
  • 10 kiloohm thermistor
  • 10 kiloohm resistor
  • SIM card (APN information required)

Software

  • Arduino IDE
  • Xampp
  • JpGraph

Bugs

Approximately every 10th connection attempt fails. It is unknown if the malfunction is related to the service provider or if other factors influence this behaviour (maybe weather?). If you have experiences concerning this problem you're welcome to leave a comment.

Potential for Improvement

Regular time intervals

At the moment the time value belonging to the measurement is defined when the measurement is written to the database. Because the time to build the connection to the GSM network varies, the time intervals are irregular.

To achieve precise time intervals a software solution as described here or a real time clock breakout could be used.

Save energy

Because the GSM modem is constantly powered and builds up connections frequently, the solution is rather energy demanding. To save energy and therefore improve the duration when powered by a battery pack, the measurements could be stored in an array and get uploaded in a bundle. This would allow the GSM Shield to be shut down for most of the time but would also require a method to determine the time locally on the arduino. Hopefully this solution would also solve the Bug at the same time.

Step 1: Webserver

Xampp

The functionality of the project was tested with the Webserver bundle Xampp. Installing a webserver locally on your machine is useful for development and testing purposes. For logging data on a long term basis it would be advised to rent a webspace from a hosting service.

Firewall

For the webserver to function properly an exception has to be added to the firewall to allow the service to connect to the internet.

Port forwarding

If your computer is part of a wireless network you'll have to set up your router to forward port 80 to your network IP address.

Step 2: Webserver Scripts

The zip file contains a folder containing five php scripts. Simply copy the folder to the htdocs folder in your Xampp directory.

config.php

This is the only file you'll have to change.

Change the database login information according to your setup. You'll have to define a security key, which the arduino passes on to the webserver, to prevent unauthorized access.

install.php

This script sets up a database and table to write to.

If you're running a fresh Xampp install you should be able to run install.php without modifying config.php.

Allthough, to keep your database safe you should set a password for the root user in phpMyAdmin.

pass.php

Arduino calls this script via the GSM network and passes the collected data on. The script stores the value to the database along with the current time and the ip address the value is coming from.

plot.php

This script uses the library JpGraph to plot the values in a graph. You'll have to download JpGraph and place it in your htdocs directory before being able to execute this script.

csv.php

This script writes the collected values to a csv file for further usage (for example in excel or the statistical computing program R).

Step 3: Thermistor Circuit

Picture of Thermistor Circuit

Arduinos analog in pins can read a voltage between 0 and 5 Volts and convert it to a number between 0 and 1023.
If solemnly the thermistor was connected to the input, the current would change proportional to the resistance instead of the voltage.

To achieve a change of voltage proportionally to the resistance we have to build a voltage divider circuit. By doing this the maximum voltage won't lie at 5 volt anymore, so we have to tell the Arduino what the new reference voltage is (Aref).

Step 4: Arduino Setup and Code

If you're using Arduino Mega or Leonardo follow the instructions for using the GSM Shield with these builds. This step is necessary for the serial communication between arduino and your computer.

Configure the setup variables in the arduino code for your web server, APN and thermistor circuit and information.

Upload the sketch and execute. Open the Serial Monitor in the Arduino IDE to check the functionality and for debugging.

Step 5:

Picture of

Comments

aaggarwal (author)2016-06-08

i was not able to connect to the server and getting status as 2. Please advice

datatrans (author)aaggarwal2016-06-08

Hi aaggarwal. Thx for trying out my solution. I'm not shure what you mean with "status as 2". Can you provide further information? Are the scripts working by them self? If you call "http://localhost/datatransfer/pass.php?data=22&check=yourkey" does it write the values to your Database? Are you able to connect to your wireless Lan with the test scripts from the GSM Library?

skjha2k (author)2015-09-13

Thank you very much. It is helping me a lot for one of my Project!

giga tm (author)2015-05-29

thank you man your project was really helpful and you really saved me a lot of work

i want to mention that the code is working but there is a simple mistake at the arduino http request you have to modifie the ? with &

also i host this at hostinger.com.ar witch is free

so now i can access the data via my free website

thank you you rock

Bangalaman (author)giga tm2015-06-05

@giga tm where is the code please ?

datatrans (author)Bangalaman2015-06-29

The code is stated in step 4:

https://www.instructables.com/files/orig/F2J/7RWJ/HXUC0IM4/F2J7RWJHXUC0IM4.zip

datatrans (author)giga tm2015-06-29

Thanks for your feedback. Glad the project is helpful to you. Is the setup working realiable for you? Any connection problems?

Bangalaman (author)2015-06-05

where is the code please

giga tm (author)Bangalaman2015-06-05

can't you see them .there are two files to be downloaded hit the // view all the instruction // and click on them

and for the code arduino side and server side you have to change it to your need change the variables .....

and for the hosting i have used a free hosting here is the link http://api.hostinger.com.ar/redir/9194711

About This Instructable

4,620views

42favorites

License:

More by datatrans:Data transmission of non-internet connected solar systems with Arduino, PHP and MySQL
Add instructable to: