Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ========
- OUTPUT
- ========
- Print 1
- e[0]=453768097,57,0,18,0,0,0,12.05,1,0,29.38,1,3,0.000000,0.000000,0,0&e[1]=453768097,280,0,18,0,0,0,12.05,1,0,29.38,1,4,0.000000,0.000000,0,0&e[2]=453768103,260,0,25,0,0,0,12.07,1,0,29.38,1,5,0.000000,0.000000,0,0&e[3]=453768133,260,0,52,1,0,0,12.07,1,0,29.38,1,6,0.000000,0.000000,0,0&e[4]=453768163,260,0,79,1,0,0,12.05,1,0,29.44,1,7,0.000000,0.000000,0,0&e[5]=453768194,260,0,107,2,0,0,12.07,1,0,29.44,1,8,51.823174,-2.274259,8,296&e[6]=453768224,260,0,134,2,0,0,12.07,1,0,29.44,1,9,51.823135,-2.274335,7,302&e[7]=453768254,260,0,161,3,0,0,12.07,1,0,29.50,1,10,51.823219,-2.274303,7,306&e[8]=453768284,260,0,189,3,0,0,12.05,1,0,29.44,1,11,51.823204,-2.274276,8,301&e[9]=453768300,250,0,203,3,0,0,12.05,1,0,29.38,1,12,51.823185,-2.274290,7,294&e[10]=453768314,260,0,216,4,0,0,12.08,1,0,29.38,1,13,51.823196,-2.274289,7,303&e[113,3,0,0,12.05,1,0,29.38,1,12,51.823185,-2.274290,7,294&e[10]=453768314,260,0,216,4,0,0,12.08,1,0,29.38,1,13,51.8239,-.728,,33e11]=453768344,260,0,243,4,0,0,12.07,1,0,29.38,1,14,51.823254,-2.274278,8,295&e[12]=453768374,260,0,270,5,0,0,12.07,1,0,29.38,1,15,51.823185,-2.274331,6,307&e[13]=453768404,260,0,298,5,0,0,12.07,1,0,29.38,1,16,51.823303,-2.274270,7,307&e[14]=453768434,260,0,325,6,0,0,1254,-2.27428,,25e12=53634,6,020,,,,1.7,,,9.81,5518385-.7431607e[3=53680,60029,,,01.0,,,2.8,,6518233-22420730&[1]437834200,2,60012.05,1,0,29.50,1,17,51.823174,-2.274287,6,311&e[15]=453768464,260,0,352,6,0,0,12.05,1,0,29.50,1,18,51.823112,-2.274347,8,301&e[16]=453768494,260,0,379,7,0,0,12.07,1,0,29.50,1,19,51.823132,-2.274336,8,303&e[17]=453768524,260,0,407,7,0,0,12.07,1,0,29.50,1,20,51.823166,-2.274347,8,302&e[18]=453768552,210,1,433,7,0,0,12.07,1,0,29.50,1,4378,0&[1]45789,6,039,,,,1.7,,,9.01,9518312-.2436830&[7]43782,200,0,,00120,,02.5,,0,1821,-.734,,32e18=43655,10143,,,01.7,,,2.01,21,51.823132,-2.274286,7,1167&e[19]=453768554,260,2,434,8,0,0,12.03,1,0,29.50,1,22,51.823135,-2.274290,7,508&e[20]=453768555,220,0,435,8,0,0,12.07,1,0,29.50,1,23,51.823132,-2.274286,7,402&e[21]=453768555,270,0,435,8,0,0,12.07,1,0,29.50,1,24,51.823132,-2.274286,7,425&
- Print 2
- e[0]=453768097,57,0,18,0,0,0,12.05,1,0,29.38,1,3,0.000000,0.000000,0,0&e[1]=453768097,280,0,18,0,0,0,12.05,1,0,29.38,1,4,0.000000,0.000000,0,0&e[2]=453768103,260,0,25,0,0,0,12.07,1,0,29.38,1,5,0.000000,0.000000,0,0&e[3]=453768133,260,0,52,1,0,0,12.07,1,0,29.38,1,6,0.000000,0.000000,0,0&e[4]=453768163,260,0,79,1,0,0,12.05,1,0,29.44,1,7,0.000000,0.000000,0,0&e[5]=453768194,260,0,107,2,0,0,12.07,1,0,29.44,1,8,51.823174,-2.274259,8,296&e[6]=453768224,260,0,134,2,0,0,12.07,1,0,29.44,1,9,51.823135,-2.274335,7,302&e[7]=453768254,260,0,161,3,0,0,12.07,1,0,29.50,1,10,51.823219,-2.274303,7,306&e[8]=453768284,260,0,189,3,0,0,12.05,1,0,29.44,1,11,51.823204,-2.274276,8,3,0,161,3,0,0,12.07,1,0,29.50,1,10,51.823219,-2.274303,7,306&e[8]=453768284,260,0,189,3,0,0,12.05,1,0,29.44,1,11,51.8230,-2747,,301&e[9]=453768300,250,0,203,3,0,0,12.05,1,0,29.38,1,12,51.823185,-2.274290,7,294&e[10]=453768314,260,0,216,4,0,0,12.08,1,0,29.38,1,13,51.823196,-2.274289,7,303&e[11]=453768344,260,0,243,4,0,0,12.0300,250,0,203,3,0,0,12.05,1,0,29.38,1,12,51.823185,-22490729&[0]45781420,,1,400,20,10293,,1,1.216,2.729,,03e1]=5763426024,,001.07,1,0,29.38,1,14,51.823254,-2.274278,8,295&e[12]=453768374,260,0,270,5,0,0,12.07,1,0,29.38,1,15,5293,,1,1.216,2.729,,03e1]=5763426024,,001.07,1,0,29.38,1,14,51.823254,-2.274278,8,295&e[12]=453768374,260,0,27,500127,10298,11,51.823185,-2.274331,6,307&e[13]=453768404,260,0,298,5,0,0,12.07,1,0,29.38,1,16,51.823303,-2.274270,7,307&e[14]=453768434,2674,260,0,27,500127,10298,11,51.823185,-2.274331,6,307&e[13]=453768404,260,0,298,5,0,0,12.07,1,0293,11,5.230,2.720,,07e1]=57644260,0,325,6,0,0,12.05,1,0,29.50,1,17,51.823174,-2.274287,6,311&e[15]=453768464,260,0,352,6,0,0,12.05,1,0,29.50,1,18,51.823112,-2.274347,8,301&e[16]=453768494,260,0,379,7,0,0,12.07,1,0,29.50,1,19,51.823132,-2.274336,8,303&e[17]=453768524,260,0,407,7,0,0,12.07,1,0,29.50,1,20,51.823166,-2.274347,8,302&e[18]=453768552,210,1,433,7,0,0,12.07,1,0,29.50,1,21,51.823132,-2.274286,7,1167&e[19]=453768554,260,2,434,8,0,0,12.03,1,0,29.50,1,22,51.823135,-2.274290,7,508&e[20]=453768555,220,0,435,8,0,0,12.07,1,0,29.50,1,23,51.823132,-2.274286,7,402&e[21]=453768555,270,0,435,8,0,0,12.07,1,0,29.50,1,24,51.823132,-2.274286,7,425&
- Print 3
- e[0]=453768097,57,0,18,0,0,0,12.05,1,0,29.38,1,3,0.000000,0.000000,0,0&e[1]=453768097,280,0,18,0,0,0,12.05,1,0,29.38,1,4,0.000000,0.000000,0,0&e[2]=453768103,260,0,25,0,0,0,12.07,1,0,29.38,1,5,0.000000,0.000000,0,0&e[3]=453768133,260,0,52,1,0,0,12.07,1,0,29.38,1,6,0.000000,0.000000,0,0&e[4]=453768163,260,0,79,1,0,0,12.05,1,0,29.44,1,7,0.000000,0.000000,0,0&e[5]=453768194,2,12.07,1,0,29.38,1,6,0.000000,0.000000,0,0&e[4]=453768163,260,0,79,1,0,0,12.05,1,0,29.44,1,7,0.000000,0.000000,0,0&e[5]=453789,260,0,107,2,0,0,12.07,1,0,29.44,1,8,51.823174,-2.274259,8,296&e[6]=453768224,260,0,134,2,0,0,12.07,1,0,29.44,1,9,51.823135,-2.274335,7,302&e[7]=453768254,260,0,161,3,0,0,12.07,1,0,29.50,1,10,51.8232112.07,1,0,29.44,1,8,51.823174,-2.274259,8,296&e[6]=43622,60014,,,01.7,,,2.41,,1.215,2.735732&[]=5782426,,6130,,20710,95,11,5.2219,-2.274303,7,306&e[8]=453768284,260,0,189,3,0,0,12.05,1,0,29.44,1,11,51.823204,-2.274276,8,301&2.735732&[]=5782426,,6130,,20710,95,11,5.2219,-2.274303,7,306&e[8]=453768284,260,0,189,3,0,0,12.05,1,0,29.44,1115.8204-.746,831&e[9]=453768300,250,0,203,3,0,0,12.05,1,0,29.38,1,12,51.823185,-2.274290,7,294&e[10]=45376,0,189,3,0,0,12.05,1,0,29.44,1115.8204-.746,831&e[9]=453768300,250,0,203,3,0,0,12.05,1,0,29.38,1,12,51.823185,-2.2729,,94e10=5768314,260,0,216,4,0,0,12.08,1,0,29.38,1,13,51.823196,-2.274289,7,303&e[11]=453768344,260,0,243,4,0,0,12.07,1,0,29.38,1,14,51.823254,-2.274278,8,295&e[12]=453768374,260,0,270,5,0,0,12.07,1,0,29.38,1,15,51.823185,-2.274331,6,307&e[13]=453768404,260,0,298,5,0,0,12.07,1,0,29.38,1,16,51.823303,-2.274270,7,307&e[14]=453768434,260,0,325,6,0,0,12.05,1,0,29.50,1,17,51.823174,-2.274287,6,311&e[15]=453768464,260,0,352,6,0,0,12.05,1,0,29.50,1,18,51.823112,-2.274347,8,301&e[16]=453768494,260,0,379,7,0,0,12.07,1,0,29.50,1,19,51.823132,-2.274336,8,303&e[17]=453768524,260,0,407,7,0,0,12.07,1,0,29.50,1,20,51.823166,-2.274347,8,302&e[18]=453768552,210,1,433,7,0,0,12.07,1,0,29.50,1,21,51.823132,-2.274286,7,1167&e[19]=453768554,260,2,434,8,0,0,12.03,1,0,29.50,1,22,51.823135,-2.274290,7,508&e[20]=453768555,220,0,435,8,0,0,12.07,1,0,29.50,1,23,51.823132,-2.274286,7,402&e[21]=453768555,270,0,435,8,0,0,12.07,1,0,29.50,1,24,51.823132,-2.274286,7,425&
- ===============
- FUNCTION
- ===============
- // Define the event log struct
- typedef struct {
- unsigned long timestamp; // Timestamp when the event was generated
- int reason; // The reason why the event was added
- int state; // The LED state, wake, sleep etc.
- unsigned long rotations; // Number of rotations the wheel has done
- unsigned int on_time; // Number of seconds the device has been awake
- unsigned int half_on_time; // Number of seconds the lights have been half on
- unsigned int full_on_time; // Number of seconds the lights have been fully on
- float voltage; // The battery voltage
- unsigned int messages_sent; // The number of messages the device has sent
- unsigned int messages_failed; // The number of messages that were attempted but failed
- float temperature; // The temperature
- int moving; // Whether we're moving
- unsigned int event_number; // The event number
- double lat; // Current latitude
- double lng; // Current longitude
- unsigned int sats; // Number of satelites involved
- unsigned int age; // Milliseconds since last fix
- } Events;
- // Make an event_log object with MAX_EVENT_LOG possible entries
- #define MAX_EVENT_LOG 45
- Events event_log[MAX_EVENT_LOG];
- Events tmp_event_log[MAX_EVENT_LOG];
- int current_event = 0;
- int tmp_current_event = 0;
- char post_data[7000];
- void sendEvents() {
- if (sending) {
- #ifdef SER_DEBUG
- mySerial.println(F("Already sending, please wait!"));
- #endif
- } else {
- sending = true;
- // Add an event to say that we tried to send
- addEvent(SENDING);
- // Duplicate event list
- memcpy(tmp_event_log, event_log, sizeof(tmp_event_log));
- tmp_current_event = current_event;
- int bytes_to_send = 0;
- // Clear the POST data array
- memset(post_data, 0, sizeof(post_data));
- Serial.print("Start: ");
- Serial.println(millis());
- noInterrupts(); // Stop interrupts while we fill the array
- for (int p = 0; p < tmp_current_event; p++) {
- char row[150];
- char *row_pos = row;
- memset(row, 0, sizeof(row)); // Make sure its zerod out
- char int_buf[15];
- char long_buf[20];
- char float_buf[15];
- // Add 'e[x]='
- char param_number_tmp[4];
- strcpy(row_pos, "e[");
- strcat(row_pos, itoa(p, param_number_tmp, 10));
- strcat(row_pos, "]=");
- // Add the timestamp to the POST string
- memset(long_buf, 0, sizeof(long_buf)); // Reset the long buffer
- ltoa(tmp_event_log[p].timestamp, long_buf, 10); // Convert the long to char array
- strcat(row_pos, long_buf); // Add the buffer to the row char array
- // Add event reason
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf)); // Reset the int buffer
- itoa(tmp_event_log[p].reason, int_buf, 10);
- strcat(row_pos, int_buf); // Add to the row
- // Add the device state
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf)); // Reset the int buffer
- itoa(tmp_event_log[p].state, int_buf, 10);
- strcat(row_pos, int_buf); // Add to the row
- // Add rotations
- strcat(row_pos, ",");
- memset(long_buf, 0, sizeof(long_buf)); // Reset the int buffer
- ltoa(tmp_event_log[p].rotations, long_buf, 10);
- strcat(row_pos, long_buf);
- // Add on time
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf)); // Reset the int buffer
- itoa(tmp_event_log[p].on_time, int_buf, 10);
- strcat(row_pos, int_buf);
- // Add half on time
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf)); // Reset the int buffer
- itoa(tmp_event_log[p].half_on_time, int_buf, 10);
- strcat(row_pos, int_buf);
- // Add full on time
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf)); // Reset the int buffer
- itoa(tmp_event_log[p].full_on_time, int_buf, 10);
- strcat(row_pos, int_buf);
- // Add voltage
- strcat(row_pos, ",");
- memset(float_buf, 0, sizeof(float_buf)); // Reset the float buffer
- dtostrf(tmp_event_log[p].voltage, 2, 2, float_buf);
- strcat(row_pos, float_buf);
- // Add messages sent
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf)); // Reset the int buffer
- itoa(tmp_event_log[p].messages_sent, int_buf, 10);
- strcat(row_pos, int_buf);
- // Add messages failed
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf)); // Reset the int buffer
- itoa(tmp_event_log[p].messages_failed, int_buf, 10);
- strcat(row_pos, int_buf);
- // Add temperature
- strcat(row_pos, ",");
- memset(float_buf, 0, sizeof(float_buf)); // Reset the float buffer
- dtostrf(tmp_event_log[p].temperature, 2, 2, float_buf);
- strcat(row_pos, float_buf);
- // Add moving
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf)); // Reset the int buffer
- itoa(tmp_event_log[p].moving, int_buf, 10);
- strcat(row_pos, int_buf);
- // Add event number
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf)); // Reset the int buffer
- itoa(tmp_event_log[p].event_number, int_buf, 10);
- strcat(row_pos, int_buf);
- // Add latitude
- strcat(row_pos, ",");
- memset(float_buf, 0, sizeof(float_buf)); // Reset the float buffer
- dtostrf(tmp_event_log[p].lat, 3, 6, float_buf);
- strcat(row_pos, float_buf);
- // Add longitude
- strcat(row_pos, ",");
- memset(float_buf, 0, sizeof(float_buf)); // Reset the float buffer
- dtostrf(tmp_event_log[p].lng, 3, 6, float_buf);
- strcat(row_pos, float_buf);
- // Add the number of satellites
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf)); // Reset the int buffer
- itoa(tmp_event_log[p].sats, int_buf, 10);
- strcat(row_pos, int_buf);
- // Add the fix age
- strcat(row_pos, ",");
- memset(int_buf, 0, sizeof(int_buf));
- itoa(tmp_event_log[p].age, int_buf, 10);
- strcat(row_pos, int_buf);
- // Add the row to the POST data string
- strcat(post_data, row);
- strcat(post_data, "&");
- }
- interrupts(); // Restart interrupts now we're done with the array
- Serial.print("End: ");
- Serial.println(millis());
- Serial.println(post_data);
- Serial.println(post_data);
- Serial.println(post_data);
- #ifdef SER_DEBUG
- mySerial.print(F("POST: "));
- mySerial.println(post_data);
- mySerial.print(F(" ["));
- mySerial.print(strlen(post_data));
- mySerial.println(F("b]"));
- #endif
- // Now we'll send the data
- asyncbee.sendPOST((int) strlen(post_data));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement