Hi all,
weiß jemand, warum ich in C/C++ mit dem Befehl time(NULL) einen falschen Wert bekomme?
ca. 14:07 Unix-timestamp:
in C: 2130385884 sec
php: liefert 1458911223 sec
Ich möchte gerne den Timestamp zu einem Sensormodul (nRF24L01+) senden, zwengs Messwertzuordnungen.
Alles funktioniert wie gewünscht, außer Timestamp (.. und deuten des 1-Wire DS18B20 Messwerts - frag ich weiter unten auch gleich)
Auszug vom Pi2-Code:
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <RF24/RF24.h>
#include <stdio.h>
#include <time.h>
using namespace std;
//g++ -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv7-a -mtune=arm1176jzf-s -Wall -I../ -lrf24-bcm mytest.cpp -o test2
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
const uint64_t addresses[] = { 0x65646f4e31,0x65646f4e32};
unsigned long startTime, stopTime, counter, rxTimer=0;
int main(int argc, char** argv){
radio.begin();
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
uint8_t stamp[4] ;
* stamp = time(NULL);
radio.write( &stamp, sizeof(stamp)) ;
cout << "stamp: " << (unsigned long)&stamp << endl;
radio.startListening();
// hier dann das Messwert Empfangszeug
}
Zwengs 1-Wire Tempsensor DS18B20.
Vielleich weiß das auch Jemand?
Laut Datenblatt :
BYTE 0 TEMPERATURE LSB (50h)
BYTE 1 TEMPERATURE MSB (50h) (85°C)
Byte 1 Byte 0
S S S S S B6 B5 B4 - B3 B2 B1 B0 -1 -2 -3 -4
Ich bekomme MSB 136 LSB 45 (Byte1,0) Zimmertemp: ca. 20,9°C
1000 1000 - 0010 1101
Also: 2,13°C - (könnt natürlich 21,3 sein - dann deut ich aber das DB falsch)
Beim ATTiny84:
..
Sensor.reset();
Sensor.skip();
Sensor.write(0xBE,1); // Read Scratchpad Byte0 LSB byte1 MSB
for ( int i = 0; i < 2; i++) { // 9 bytes brauch nur 2 davon laut Datenblatt
temp[i] = Sensor.read();
}
..
Viele Grüße aus LA
ralphi
"Nicht alles was einfach ist, ist genial, aber alles was genial ist, ist einfach" - Albert E.