Connect Arduino and phpMyadmin

With the code I posted, you should be able to figure out how to read the Dallas temp IC and send that value. If you are looking for a plug-n-play program from me, I charge for that, and I feel I am already at that point.

There is a difference between helping someone with their homework, and doing it for them. :wink:

      client.print("GET /test_database.php?t");     // the database based on your post about php before         
             
     client.println(temp1);

If the temperature is 17.5 degrees, the GET command will be:
GET /test_database.php?t17.5

Does that make sense? The only _GET key/value pair that will be populated will be t17.5, with a blank value.

SurferTim you are totally right and i am really grateful for your help. Thank you very much. I did not want to get the work done by you and i am sorry again if i gave you that impression. You have already helped me more than i expected. Thank you very much again

Just for the record. When i try to open phpMyadmin it keeps showing the following message:

import.php: Missing parameter: import_type
import.php: Missing parameter: format

Does anyone have any advice? Could this be the problem?

That I will help you with. I check using the command line interface to mysql. From a terminal on the server

mysql -uuser -ppassword databasename

Replace user, password, and databasename with the settings in the php code.

Then when in mysql

select * from temperatures;

What is there?

edit: Now I am back to helping you, not doing it for you.
This method using the command line is also a really good way to check your mysql commands and the formats if you have a question before trying it on the php page.

Sorry but i don't quite understand what you ask me to do. I open terminal on XAMPP and then do what you said? Where exactly should i do that?

You should get a command prompt when you open a terminal window. At the prompt, enter the mysql line above. You should get a message from mysql, then a mysql prompt instead of the terminal prompt. When you are finished, type "exit" to close mysql. You should return to a terminal prompt at that point.

Ok, i type cmd and open a command prompt, then i type "mysql -uuser -ppassword databasename" (with my data) but tells me "mysql is not recognized as an internal or external command etc etc..."

That was on your server? No mySQL? Are you certain you have mysql installed on your Apache server?

I have installed XAMPP that already has phpMyadmin

I have two flavors of Linux (PCLinuxOS and Ubuntu) with two versions of PCLinuxOS and two versions of Ubuntu, and all respond to mysql at a command prompt.

This is a Linux OS, right?

No, WIndows...

chris87:
No, WIndows...

I have one Windows computer for client testing only. My servers are Linux. Maybe a Windows XAMPP user will show up.

Whatever... Thanks a lot...Again...

Maybe a Windows XAMPP user will show up.

Opening a command window inherits the PATH variable. The definition appears to not know where mySQL is installed.

The phpMyAdmin function DOES know where mySQL is installed.

If you modify the PATH variable to include where mySQL is installed, then you can execute mysQL commands from anywhere. Otherwise, you need to cd to the directory where mySQL is installed.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,2);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress server(1,2,3,4); // Change to your server ip
EthernetClient client;
int totalCount = 0;
int loopCount = 0;


// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 9

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();

  // locate devices on the bus
  Serial.print("Locating devices...");
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");

  // assign address manually.  the addresses below will beed to be changed
  // to valid device addresses on your bus.  device address can be retrieved
  // by using either oneWire.search(deviceAddress) or individually via
  // sensors.getAddress(deviceAddress, index)
  //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
  //outsideThermometer   = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };

  // search for devices on the bus and assign based on an index.  ideally,
  // you would do this to initially discover addresses on the bus and then 
  // use those addresses and manually assign them (see above) once you know 
  // the devices on your bus (and assuming they don't change).
  // 
  // method 1: by index
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1"); 

  // method 2: search()
  // search() looks for the next device. Returns 1 if a new address has been
  // returned. A zero might mean that the bus is shorted, there are no devices, 
  // or you have already retrieved all of them.  It might be a good idea to 
  // check the CRC to make sure you didn't get garbage.  The order is 
  // deterministic. You will always get the same devices in the same order
  //
  // Must be called before search()
  //oneWire.reset_search();
  // assigns the first address found to insideThermometer
  //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
  // assigns the seconds address found to outsideThermometer
  //if (!oneWire.search(outsideThermometer)) Serial.println("Unable to find address for outsideThermometer");

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();

  Serial.print("Device 1 Address: ");
  printAddress(outsideThermometer);
  Serial.println();

  // set the resolution to 9 bit
  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);

  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC); 
  Serial.println();

  Serial.print("Device 1 Resolution: ");
  Serial.print(sensors.getResolution(outsideThermometer), DEC); 
  Serial.println();
  
    pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(2000);
  Serial.println("Ready");
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    // zero pad the address if necessary
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print("Temp C: ");
  Serial.print(tempC);
  Serial.print(" Temp F: ");
  Serial.print(DallasTemperature::toFahrenheit(tempC));
}

// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
  Serial.print("Resolution: ");
  Serial.print(sensors.getResolution(deviceAddress));
  Serial.println();    
}

// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
  Serial.print("Device Address: ");
  printAddress(deviceAddress);
  Serial.print(" ");
  printTemperature(deviceAddress);
  Serial.println();
}
char pageAdd[32];
void loop(void)
{ 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");

  // print the device information
  printData(insideThermometer);
  printData(outsideThermometer);
  
  
    if(loopCount < 30)
  {
    delay(1000);
  }
  else
  {
    loopCount = 0;
    sprintf(pageAdd,"/test.php?temp1=%d",totalCount);
    if(!getPage(server,pageAdd)) Serial.print("Fail ");
    else Serial.print("Pass ");
    totalCount++;
    Serial.println(totalCount,DEC);
  }    
  loopCount++;
  
}
byte getPage(IPAddress ipBuf,char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print("connecting...");

  if(client.connect(ipBuf,80))
  {
    Serial.println("connected");

    sprintf(outBuf,"GET %s HTTP/1.0\r\n\r\n",page);
    client.write(outBuf);
  } 
  else
  {
    Serial.println("failed");
    return 0;
  }

  int connectLoop = 0;
  
  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      connectLoop = 0;
    }

    delay(10);
    connectLoop++;
    if(connectLoop > 1000)
    {
      Serial.println();
      Serial.println("Timeout");
      client.stop();
    }
    
  }

  Serial.println();

  Serial.println("disconnecting.");
  client.stop();

  return 1;

}

Hi am new in Arduino and i want to make a present to my dad. The project as you see below is to read two temperatures and send them to a database. I read all the topic and a make the code above that print serial the temperatures. Please can you help me what i need to do now for having this data on a database?

Thanks in advance

You will need a html/php (Linux) or html/asp (Windows)server. What do you plan on using?

I already have a Linux server

So do I. Read replies #13 and #15 for the code.

At reply 15 that you said to save this code as arduino.php, is this php code or for arduino??