Hi,
i am trying to send a data package to a server with this Code:
#include
// Plug on P1 for testing the button and the LED.
Port connector(1);
// Variables for the 5 different counters
int intcount,sendingsdone = 0;
int counters[5];
byte status = 0;
byte radioIsOn;
// counter for sending every 15 seconds
MilliTimer countTimer;
typedef struct {
unsigned int device;
unsigned int count1;
unsigned int count2;
unsigned int count3;
unsigned int count4;
unsigned int count5;
} counterdata;
static void lowPower (byte mode) {
// disable the ADC
byte prrSave = PRR, adcsraSave = ADCSRA;
ADCSRA &= ~ bit(ADEN);
PRR &= ~ bit(PRADC);
// go into power down mode
setsleepmode(mode);
sleepmode();
// re-enable the ADC
PRR = prrSave;
ADCSRA = adcsraSave;
}
void setup () {
connector.mode(OUTPUT);
connector.digiWrite(1);
connector.mode2(INPUT); // Set AIO mode as input
connector.digiWrite2(1); // Activate pull-up resistor for
// Serial for testing and Rf12 for sending
Serial.begin(57600);
rf12config();
rf12easyInit(0);
for (int i=0;i<5;i++) {
counters[i] = 0;
}
lowPower(SLEEPMODEIDLE);
radioIsOn = 1;
}
void loop () {
// This button block is for counting the button press
// At the first 10 sendings the LED should show if the button was pressed.
// After 10 sendings the LED should be off
byte pushed = connector.digiRead2();
if (radioIsOn && rf12easyPoll() == 0) {
rf12sleep(0); // turn the radio off
radioIsOn = 0;
Serial.print("off");
}
if (pushed == 0 && status == 0){
status =1;}
if (pushed == 1 && status == 1){
status =0;
counters[intcount] +=1;
if (sendingsdone<=10) {
connector.digiWrite(0);
delay(100);
connector.digiWrite(1);
}
}
// In this block the same output on the Serial console should be send over RF12.
// The Output on the recieving PC (RF12 Jeelink) should be look like this "Logger1=0=0=0=0=0"
// All 15 seconds (intcoundcountTimer (35)) the new data should be send.
if ( intcount==5) {
sendingsdone+=1;
counterdata sendcount;
sendcount.device = 192;
sendcount.count1 = counters[0];
sendcount.count2 = counters[1];
sendcount.count3 = counters[2];
sendcount.count4 = counters[3];
sendcount.count5 = counters[4];
char sending = rf12easySend(&sendcount, sizeof sendcount);
if (sending) {
// make sure the radio is on again
if (!radioIsOn)
rf12sleep(-1); // turn the radio back on
radioIsOn = 1;
Serial.print("on");
}
Serial.print("Logger1");
for (int i=0;i<5;i++){
Serial.print("=");
Serial.print(countersi;
}
Serial.print("\n");
for (int i=0;i<5;i++) {
counters[i] = 0;
}
intcount=0;
}
// The timer for changing the counter variables
if (countTimer.poll(3000)) {
intcount+=1;
}
}
I hope someone can tell me why i get this Output after pressing the button 2 times:
Logger=192=0=0=0=0=2 Logger=192=0=0=0=0=2 Logger=192=0=0=0=0=2 Logger=192=0=0=0=0=2 Logger=192=0=0=0=0=2 Logger=192=0=0=0=0=2 Logger=192=0=0=0=0=2
I don't understand why the Server gets the data more than one time?
thanks a lot.
Cu kami
