Hi
I want to send the output from my DS18B20 device . I see the temp on the serial port but the
my server don’t get it .
This is my code please help TNX
#include <DallasTemperature.h>
#include <OneWire.h>
#include <Wire.h>
#define DS18S20_ID 0x10
#define DS18B20_ID 0x28
#define HTTP_TIMEOUT 10000
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
MilliTimer tReply;
static boolean httpHaveReply;
//---------------------------------------------------------------------
// The PacketBuffer class is used to generate the json string that is send via ethernet - JeeLabs
//---------------------------------------------------------------------
class PacketBuffer :
public Print {
public:
PacketBuffer () :
fill (0) {
}
const char* buffer() {
return buf;
}
byte length() {
return fill;
}
void reset()
{
memset(buf,NULL,sizeof(buf));
fill = 0;
}
virtual size_t write (uint8_t ch)
{
if (fill < sizeof buf) buf[fill++] = ch;
}
byte fill;
char buf[150]; // Might need to be set higher if long strings need to be sent (Be carefull to stay within ram limits)
private:
};
PacketBuffer str;
// ethernet interface mac address, must be unique on the LAN
static byte mymac = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
unsigned long timer;
char website PROGMEM = “poolmanager.cloudapp.net”;
void setup ()
{
Serial.begin(9600);
// Serial.println(“03 - Basic Web Client”);
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( “Failed to access Ethernet controller”);
// Set to true and enter IP to give the NanodeRF a static IP address - default is DHCP (NB: must be used with static server IP (hisip)
// DHCP Setup
if (!ether.dhcpSetup())
//Serial.println(“DHCP failed”);
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
// DNS Setup
if (!ether.dnsLookup(website))
// Serial.println(“DNS failed”);
ether.printIp("SRV: ", ether.hisip);
}
int DS18B20_Pin = 8; //DS18S20 Signal pin on digital 2
//Temperature chip i/o
OneWire ds(DS18B20_Pin); // on digital pin 8
void loop () {
ether.packetLoop(ether.packetReceive());
int error=0;
float temperature = getTemp();
byte b1 = temperature; // Get the integer part (678).
float e4 = temperature - b1; // Get fractional part (678.0123 - 678 = 0.0123).
byte b2 = trunc(e4 * 1000); // Turn into integer (123).
str.reset();
str.print("{Temp:");
str.print(b1);
str.print(".");
str.print(b2);
str.print("}");
Serial.println(“Request sent TEMP”);
Serial.println( str.buf);
// Send some test data to the server:
ether.browseUrl(PSTR("/input/post.json?apikey=9d08ab824d1ee7248e82ef2d00454b8b&json="),str.buf ,website, 0);
// Wait for reply
tReply.set(HTTP_TIMEOUT);
while (!httpHaveReply) {
ether.packetLoop(ether.packetReceive());
if (tReply.poll()) {
error=1; // network timeout
break;
}
}
}
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println(“CRC is not valid!”);
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print(“Device is not recognized”);
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(1000);
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data = ds.read();
-
}*
-
Serial.println(data[1]);*
-
Serial.println(data[0]);*
-
ds.reset_search();*
-
byte MSB = data[1];*
-
byte LSB = data[0];*
-
float tempRead = ((MSB << 8) | LSB); //using two’s compliment*
-
float TemperatureSum = tempRead / 16;*
-
return TemperatureSum;*
}