Writing empy data to webserver no temperature (ds18b20) results please help

Hello,

a newbe here. :frowning:
i’m following a tutorial to write temperature sensor data to a webserver.
my problem is that it writes empty data to my webserver.

my hardware:

arduino uno:
ethernet shield: w5100
temperture sensor: ds18b20

==========================================

  1. first i show you my arduino program and serial monitor output
    ==========================================

Code:

===============================

</>

#include <Ethernet.h> // Used for Ethernet
#include <OneWire.h> // Used for temperature sensor(s)

// define debug als je deze aanzet dan kun je de serial monitor gebruiken
#define DEBUG

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac = { 0x00, 0xAF, 0xBB, 0xCC, 0xDE, 0x02 };
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server = “192.168.1.102”; // IP Adres (or name) of server to dump data to
unsigned long PreviousMillis = 0;// For when millis goes past app 49 days.
unsigned long interval = 10000; // Wait between dumps (10000 = 10 seconds)
//unsigned long interval = 300000; // Wait between dumps (1 min)
unsigned long intervalTime; // Global var tracking Interval Time

// **** TEMPERATURE SETTINGS ****
// Sensor(s) data pin is connected to Arduino pin 2 in non-parasite mode!
OneWire ds(2);

void setup() {
#ifdef DEBUG
Serial.begin(9600); // only use serial when debugging
#endif

Ethernet.begin(mac);

intervalTime = millis(); // Set initial target trigger time (right NOW!)

#ifdef DEBUG
Serial.println(“Tweaking4All.com - Temperature Drone - v2.3”);
Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
Serial.print("IP Address : ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("Default Gateway IP: ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server IP : ");
Serial.println(Ethernet.dnsServerIP());
#endif
}

void loop() {
unsigned long CurrentMillis = millis();

if ( CurrentMillis < PreviousMillis ) // millis reset to zero?
{
intervalTime = CurrentMillis+interval;
}

if ( CurrentMillis > intervalTime ) // Did we reach the target time yet?
{
intervalTime = CurrentMillis + interval;

if (!client.connect(server, 80)) {
#ifdef DEBUG
Serial.println("-> Connection failure detected: Resetting ENC!"); // only use serial when debugging
#endif
Ethernet.begin(mac);
} else {
client.stop();
}

// if you get a connection, report back via serial:
if (client.connect(server, 80))
{
#ifdef DEBUG
Serial.println("-> Connected"); // only use serial when debugging
#endif

// Make a HTTP request:
client.print( “GET /arduinotemp_add_data/add_data.php?”);

TemperaturesToGetVariables(); // send serial and temperature readings

client.println( " HTTP/1.1");
client.println( “Host: 192.168.1.102” );
client.print(" Host: “);
client.println(server);
client.println( “Connection: close” );
client.println();
client.println();
client.stop();
}
else
{
// you didn’t get a connection to the server:
#ifdef DEBUG
Serial.println(”–> connection failed !!"); // only use serial when debugging
#endif

//Enc28J60.init(mac);
}
}
else
{
Ethernet.maintain();
}
}

void TemperaturesToGetVariables(void)
{
byte counter;
byte present = 0;
byte sensor_type;
byte data[12];
byte addr[8];
float celsius;
byte sensorcounter;

ds.reset_search();
sensorcounter = 1; // we start counting with sensor number 1

while ( ds.search(addr) )
{
if (sensorcounter>1) client.print("&"); // add ampersand if not first sensor

client.print(“serial”); // print: sensorx=
client.print(sensorcounter);
client.print("=");

#ifdef DEBUG
// Print Serial number
Serial.print(" Sensor : “);
Serial.println(sensorcounter);
Serial.print(” Serial : ");
#endif

for( counter = 0; counter < 8; counter++)
{
if (addr[counter]<10) client.print(“0”);
client.print(String(addr[counter], HEX));
if (counter<7) client.print("%20");

#ifdef DEBUG
if (addr[counter]<10) Serial.print(“0”);
Serial.print(String(addr[counter], HEX));
if (counter<7) Serial.print(" ");
#endif
}

#ifdef DEBUG
Serial.println(); // only use serial when debugging
#endif

client.print("&temperature"); // print: &temperaturex=
client.print(sensorcounter);
client.print("=");

// Check CRC
if (OneWire::crc8(addr, 7) != addr[7]) // print ERROR if CRC error
{
client.println(“ERROR”);
}
else // CRC is OK
{
// Removed sensor type detection and assumed DS18B20 sensor
ds.reset();
ds.select(addr);
ds.write(0x44); // start conversion, with regular (non-parasite!) power

delay(750); // maybe 750ms is enough, maybe not

present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

// Get Raw Temp Data
for ( counter = 0; counter < 9; counter++)
{ // we need 9 bytes
data[counter] = ds.read();
}

// Convert the data to actual temperature
int16_t raw = (data[1] << 8) | data[0];

// at lower res, the low bits are undefined, so let’s zero them
byte cfg = (data[4] & 0x60);

//// default is 12 bit resolution, 750 ms conversion time
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms

celsius = (float)raw / 16.0;
client.print(celsius);

#ifdef DEBUG
Serial.print(" Temperature: “);
Serial.print(celsius);
Serial.println(” C");
#endif
}

sensorcounter++;
}
return;
}

</>

Now the serial monitor output IT SEEMS TO BE OKE

===============================

IP Address : 192.168.1.80
Subnet Mask : 255.255.255.0
Default Gateway IP: 192.168.1.1
DNS Server IP : 8.8.8.8
→ Connected
Sensor : 1
Serial : 28 ff 50 7e 83 16 03 42
Temperature: 14.75 C
→ Connected
Sensor : 1
Serial : 28 ff 50 7e 83 16 03 42
Temperature: 14.75 C

===============================

  1. now i will show you my add_data.php file

===============================

<?php // Connect to MySQL include("connection.php"); $sql = "INSERT INTO temperature (sensor ,celsius) VALUES ('".$_GET["sensor"]."','".$_GET["celsius"]."')"; $conn = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE); mysqli_query($conn, $sql); ?>

============================

Results in mysql: (it’s writing records but the are empty)

event sensor celsius

2016-12-03 09:07:38 0
2016-12-03 09:07:48 0
2016-12-03 09:07:58 0
2016-12-03 09:08:08 0

=============================================

when i’m using a test url. it’s working.

http://192.168.1.102/arduinotemp_add_data/add_data.php?sensor=284444820502226b&celsius=10.00

=============================================

Can some please help at this moment i’m stuck

Welcome to the forum. If you use the code tags (</>) its much easier to read.

I suspect if you temporarily change all your “client.print” statements to serial.print you will see the problem.

My guess is this

client.print("&temperature");  // print: &temperaturex=
    client.print(sensorcounter);
    client.print("=");

which will print something like “&temperature1=14.75”

But your php script is expecting

“&celsius=14.75”

You should also modify your PHP code to deal with this better- see this stackoverflow question for some tips.

hello rw950431,

is it possible for you to change my code to a code that will work,
i can't figure it out what's going wrong
i had this tutorial from www.tweaking4all.nl/hardware/arduino/arduino-ethernet-data-push/