tuxmartin

timestamp

Jan 28th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. void Websocket::sendEnvironment()
  2. {
  3.     // current timestamp
  4.     struct timeval tv;
  5.     gettimeofday(&tv, NULL);
  6.  
  7.     Environment e;
  8.     e.set_time( (int) tv.tv_sec );
  9.     e.set_humidity( (rand() % 100 + 1) );
  10.     e.set_temperature( (rand() % 10 + 20) );
  11.  
  12.     cout << "_______________________time " << ( tv.tv_sec ) << endl;
  13.     cout << "_______________________humidity " << ( (rand() % 100 + 1) ) << endl;
  14.     cout << "_______________________temperature " << ( (rand() % 10 + 20) ) << endl;
  15.  
  16.  
  17.     Header *h(new Header);
  18.     h->set_id(cloudConnector->generateRandomNumber());
  19.     h->set_type("Environment");
  20.  
  21.     Request r;
  22.     r.set_data(e.SerializeAsString().c_str(), e.ByteSize());
  23.     r.set_allocated_header(h);
  24.  
  25.     sendMessageBinary(r.SerializeAsString().c_str(), r.ByteSize());
  26. }
  27.  
  28.  
  29. /* podle manualu:
  30.  
  31. struct timeval {
  32.     long tv_sec;                /* seconds */
  33.     long tv_usec;               /* microseconds */
  34. };
  35.  
  36. ale me z toho leze:
  37.  
  38. CLOUD:!!!_environmentRequest=▒ا▒▒▒
  39. CLOUD:_______________________time 2373
  40. CLOUD:_______________________humidity 87
  41. CLOUD:_______________________temperature 22
  42.  
  43. pritom aktualni timestamp je +-:
  44. root@meo2:~# date +%s
  45. 1453980307
  46.  
  47. */
Advertisement
Add Comment
Please, Sign In to add comment