 #endif
 
   if ( debug )
-    print_statef("got glucose(%d) at %d min, stored at %d, inc. write to ", glucose, current_time_ms/60000, Pkts.write); 
+    print_statef("got glucose(%d) at %d min, stored at %d, inc. write to ", scale_bg(glucose), current_time_ms/60000, Pkts.write); 
   // so increment write position for next round...
   if ( ++Pkts.write >= DXQUEUESIZE )
     Pkts.write = 0;

void SimbleeBLE_onDisconnect()
{
  BTconnected = false;
  print_state("+++++++++++++ BLE lost");
}

void SimbleeBLE_onConnect()
{
  BTconnected = true;
  print_state("+++++++++++++ BLE conn");
}

void SimbleeBLE_onRSSI(int rssi)

  return free_memory;
}

/*
 * print current timestamp
 */
char * current_timestamp(char *outbuffer)
{
  unsigned long ms = mymillis();

  sprintf(outbuffer, "\r\n[%03d][%03d][%03d] ", ms/60000, (ms/1000)%60, ms%1000);
  return(outbuffer);
}

void print_state(String str)
{
  char ob[80];

  Serial.printf("%s%s", current_timestamp(ob), str.cstr());
//  Serial.print(str);
}

int print_statef(const char *format, ...)
{
  va_list vl;
  char op[256];
  char *opp;

  memset(op, 0, sizeof(op));      // for 0 termination

  current_timestamp(op);          // set current timestamp

  opp = &op[strlen(op)];
  va_start(vl, format);
  
  while (*format)
  {
    if (*format == '%')
    {
      format++;
      char ch = *format;
      if (! ch)
        break;
      else if (ch == '%')
        *opp++ = *format;
      else if (ch == 'b') {
        unsigned u = va_arg(vl, unsigned);
        utoa(u, opp, 2);
        opp = &op[strlen(op)];
      }
      else if (ch == 'c') {
        int ch = va_arg(vl, int);
        *opp++ = (char)ch;
      }
      else if (ch == 'd') {
        int i = va_arg(vl, int);
        itoa(i, opp, 10);
        opp = &op[strlen(op)];
      }
      else if (ch == 'l') {
        unsigned long i = va_arg(vl, unsigned long);
        ultoa(i, opp, 10);
        opp = &op[strlen(op)];
      }
      else if (ch == 'u') {
        unsigned u = va_arg(vl, unsigned);
        utoa(u, opp, 10);
        opp = &op[strlen(op)];
      }
      else if (ch == 'x') {
        unsigned x = va_arg(vl, unsigned);
        itoa(x, opp, 16);
        opp = &op[strlen(op)];
      }
      else if (ch == 's') {
        char *s = va_arg(vl, char *);
        strcat(op, s);
        opp = &op[strlen(op)];
      }
      else if (ch == 'f') {
        char format[20];
        double d = va_arg(vl, double);
        sprintf(opp, "%d.%02d", (int)d, ((int)(d*100))%100);
        opp = &op[strlen(op)];
      }
    }
    else
     *opp++ = *format;
    format++;
  }
  
  va_end(vl);

  Serial.print(op);

  return 1;
} 

int myprintf(const char *format, ...)
{
  va_list vl;
  char op[256];
  char *opp;

  memset(op, 0, sizeof(op));  // for 0 termination
  opp = &op[0];               // set pointer to array start
  va_start(vl, format);
  
  while (*format) {
    if (*format == '%') {     // format descriptor found?
      format++;
      char ch = *format;
      if (! ch)
        break;
      else if (ch == '%')
        *opp++ = *format;
      else if (ch == 'b') {
        unsigned u = va_arg(vl, unsigned);
        utoa(u, opp, 2);
        opp = &op[strlen(op)];
      }
      else if (ch == 'c') {
        int ch = va_arg(vl, int);
        *opp++ = (char)ch;
      }
      else if (ch == 'd') {
        int i = va_arg(vl, int);
        itoa(i, opp, 10);
        opp = &op[strlen(op)];
      }
      else if (ch == 'l') {
        unsigned long i = va_arg(vl, unsigned long);
        ultoa(i, opp, 10);
        opp = &op[strlen(op)];
      }
      else if (ch == 'u') {
        unsigned u = va_arg(vl, unsigned);
        utoa(u, opp, 10);
        opp = &op[strlen(op)];
      }
      else if (ch == 'x') {
        unsigned x = va_arg(vl, unsigned);
        itoa(x, opp, 16);
        opp = &op[strlen(op)];
      }
      else if (ch == 's') {
        char *s = va_arg(vl, char *);
        strcat(op, s);
        opp = &op[strlen(op)];
      }
      else if (ch == 'f') {
        char format[20];
        double d = va_arg(vl, double);
        sprintf(opp, "%d.%02d", (int)d, ((int)(d*100))%100);
        opp = &op[strlen(op)];
      }
    }
    else
     *opp++ = *format;
    format++;
  }
  
  va_end(vl);

  Serial.print(op);

  return 1;
} 

int old_print_statef(const char *format, ...)
{
  va_list vl;
  size_t n = 0;
