SendUptime does not work (iOS 9.0.1)

Hello
I have been trying to no avail to get the BLYNK delay suggested through the SendUptime loop to work but does not appear to work.

I am trying to sample a measurement every 5 minutes. Delays just does not work as the system time out. SendUptime just does not do anything…

HELP…

Thanks

Krys

Hello, could you show your code?

Please find enclosed related code as requested. Appreciate your help.

/*
  SD card datalogger with internet NTP time updated every 24hrs.
*/

// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10  //10 for WiFi, 4 for SD//
//#define BLYNK_PRINT Serial // #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
//#define BLYNK_DEBUG // Optional, this enables lots of prints
#define WLAN_SSID "JHLW"
#define WLAN_PASS "ZbyszZdzislaw"
#define WLAN_SECURITY WLAN_SEC_WPA2
char auth[] = "abcdefghijklmnopqrstuvw"; // 


#include <SPI.h>
#include <SD.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <Time.h>
#include <BlynkSimpleCC3000.h>
#include <WidgetSD.h>
#include <SimpleTimer.h>

/*
             
*/


/*

*/


//const int timeZone = -5;//GMT-5
Adafruit_CC3000_Client client;
WidgetSD sd;

BLYNK_ATTACH_WIDGET(sd, 1);


const unsigned long
  connectTimeout  = 15L * 1000L, // Max time to wait for server connection
  responseTimeout = 15L * 1000L; // Max time to wait for data from server
int
  countdown       = 0;  // loop() iterations until next time server query
unsigned long
  lastPolledTime  = 0L, // Last value retrieved from time server
  sketchTime      = 0L; // CPU milliseconds since last server query


const int chipSelect = 4;  //4 for SD

const int sensorsConnected = 1;  //number of sensors

SimpleTimer timer;

  // Setup a function to be called every second
//timer simpleTimer;
   
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
//  Serial.begin(115200);
 
  Blynk.begin(auth, "JHLW", "1234567891011", WLAN_SEC_WPA2);  // Here your Arduino connects to the Blynk Cloud.

  // Setup a function to be called every second
  timer.setInterval(1000L, sendUptime);
  
  while (!Serial) {
   ; // wait for serial port to connect. Needed for Leonardo only
  }
Serial.print("Initializing SD card...");
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  //WiFi connect
    Serial.println(F("Hello, CC3000!\n")); 
    displayDriverMode();
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!cc3000.begin()) {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    for(;;);
  }
  uint16_t firmware = checkFirmwareVersion();
  if (firmware < 0x113) {
    Serial.println(F("Wrong firmware version!"));
    for(;;);
  } 
  displayMACAddress();

}

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000.0 );
}


void loop()  {
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer

//   simpleTimer.run();//timer for sendin g push to Blynk-Arduino
   
// To reduce load on NTP servers, time is polled once per roughly 24 hour period.
// Otherwise use millis() to estimate time since last query.  Plenty accurate.
  
 if(countdown == 0) {            // Time's up?
    unsigned long t  = getTime(); // Query time server
    if(t) {                       // Success?
      lastPolledTime = t;         // Save time
      sketchTime     = millis();  // Save sketch time of last valid time query
      countdown      = 24*60*4-1; // Reset counter: 24 hours * 15-second intervals
    }
  } else {
    countdown--;                  // Don't poll; use math to figure current time
  }

  unsigned long currentTime = lastPolledTime + (millis() - sketchTime) / 1000;
// Serial.print(F("Current UNIX time: "));
// Serial.print(currentTime);
// Serial.println(F(" (seconds since 1/1/1970 UTC)"));
  //float excelTime = (((currentTime) / ( 24.000 * 60.000 * 60.000 )) + 25568.8);//Convert to GMT-5 excel time based on 1-Jan-1990.
  //Serial.println(excelTime);
 //  digitalClockDisplay();

   
  // make a string for assembling the data to log:
  String dataString = "";
 dataString += String(currentTime);
     dataString += ",";
  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < (sensorsConnected); analogPin++) {
    float sensorValue = analogRead(analogPin);
 float volt = (sensorValue/1024.0) * 5.00 * 1.01 ;//Ref 5V 
 int  VWC = 0;  
//Volumetric Water Content for VH400 is a piecewise function of the voltage from the sensor
 if (volt < 0.00001 ) {VWC = 0;}
 else if (volt < 1.1) {VWC = (10 * volt) - 1;}
 else if (volt < 1.3) {VWC = (25 * volt) - 17.5;}
 else if (volt < 1.82) {VWC = (48.08 * volt) - 47.5;}
 else if (volt < 2.2) {VWC = (26.32 * volt) - 7.89;}
 else {VWC = (62.5 * volt) - 87.5;}    

    dataString += String(VWC);
    if (analogPin < (sensorsConnected-1)) {dataString += "%,";}
    else if (analogPin < (sensorsConnected)) {dataString += "%";
    }
 
  Blynk.virtualWrite(1, VWC);
  Blynk.virtualWrite(2, VWC);
  Blynk.virtualWrite(3, volt);
  Blynk.virtualWrite(7, millis()/ 60000.0);  


  }
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.csv", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.csv");
  }
delay(15000L);
}


//-------------------------------------------------------------------------/
/*!
    @brief  Displays the driver mode (tiny of normal), and the buffer
            size if tiny mode is not being used

    @note   The buffer size and driver mode are defined in cc3000_common.h
*/
//-------------------------------------------------------------------------/
void displayDriverMode(void)
{
  #ifdef CC3000_TINY_DRIVER
    Serial.println(F("CC3000 is configure in 'Tiny' mode"));
  #else
    Serial.print(F("RX Buffer : "));
    Serial.print(CC3000_RX_BUFFER_SIZE);
    Serial.println(F(" bytes"));
    Serial.print(F("TX Buffer : "));
    Serial.print(CC3000_TX_BUFFER_SIZE);
    Serial.println(F(" bytes"));
  #endif
}

//-------------------------------------------------------------------------/
/*!
    @brief  Tries to read the CC3000's internal firmware patch ID
*/
//-------------------------------------------------------------------------/
uint16_t checkFirmwareVersion(void)
{
  uint8_t major, minor;
  uint16_t version;
  
#ifndef CC3000_TINY_DRIVER  
  if(!cc3000.getFirmwareVersion(&major, &minor))
  {
    Serial.println(F("Unable to retrieve the firmware version!\r\n"));
    version = 0;
  }
  else
  {
    Serial.print(F("Firmware V. : "));
    Serial.print(major); Serial.print(F(".")); Serial.println(minor);
    version = major; version <<= 8; version |= minor;
  }
#endif
  return version;
}

//-------------------------------------------------------------------------/
/*!
    @brief  Tries to read the 6-byte MAC address of the CC3000 module
*/
//-------------------------------------------------------------------------/
void displayMACAddress(void)
{
  uint8_t macAddress[6];
  
  if(!cc3000.getMacAddress(macAddress))
  {
    Serial.println(F("Unable to retrieve MAC Address!\r\n"));
  }
  else
  {
    Serial.print(F("MAC Address : "));
    cc3000.printHex((byte*)&macAddress, 6);
  }
}


//-------------------------------------------------------------------------/
/*!
    @brief  Tries to read the IP address and other connection details
*/
//-------------------------------------------------------------------------/
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  
  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}

// Minimalist time server query; adapted from Adafruit Gutenbird sketch,
// which in turn has roots in Arduino UdpNTPClient tutorial.
unsigned long getTime(void) {

  uint8_t       buf[48];
  unsigned long ip, startTime, t = 0L;

  Serial.print(F("Locating time server..."));

  // Hostname to IP lookup; use NTP pool (rotates through servers)
  if(cc3000.getHostByName("pool.ntp.org", &ip)) {
    static const char PROGMEM
      timeReqA[] = { 227,  0,  6, 236 },
      timeReqB[] = {  49, 78, 49,  52 };

    Serial.println(F("\r\nAttempting connection..."));
    startTime = millis();
    do {
      client = cc3000.connectUDP(ip, 123);
    } while((!client.connected()) &&
            ((millis() - startTime) < connectTimeout));

    if(client.connected()) {
      Serial.print(F("connected!\r\nIssuing request..."));

      // Assemble and issue request packet
      memset(buf, 0, sizeof(buf));
      memcpy_P( buf    , timeReqA, sizeof(timeReqA));
      memcpy_P(&buf[12], timeReqB, sizeof(timeReqB));
      client.write(buf, sizeof(buf));

      Serial.print(F("\r\nAwaiting response..."));
      memset(buf, 0, sizeof(buf));
      startTime = millis();
      while((!client.available()) &&
            ((millis() - startTime) < responseTimeout));
      if(client.available()) {
        client.read(buf, sizeof(buf));
        t = (((unsigned long)buf[40] << 24) |
             ((unsigned long)buf[41] << 16) |
             ((unsigned long)buf[42] <<  8) |
              (unsigned long)buf[43]) - 2208988800UL;
        Serial.print(F("OK\r\n"));
      }
      client.close();
    }
  }
  if(!t) Serial.println(F("error"));
  return t;
}

void digitalClockDisplay(){
  // digital clock display of the time
  printHrs(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}
void printHrs(int digits){
  // utility for digital clock display: prints preceding colon and leading 0
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void printDigits(int digits){
  // utility for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
// This function is used by Blynk to receive data
size_t BlynkStreamRead(void* buf, size_t len)
{
  return Serial.readBytes((byte*)buf, len);
}

// This function is used by Blynk to send data
size_t BlynkStreamWrite(const void* buf, size_t len)
{
  return Serial.write((byte*)buf, len);
}

Use code wrapping to make your code readable.

I’m going to delete your messages with code. Please edit it to correspond to forum guidelines:

Wrap your code by pressing this magic button (Backtick`) 3 times (before the code and after it):

This makes your code readable with highlighted syntax, like this:

//comment goes here
void helloWorld() {
   String message =  "hello" + "world";
}

You can also select the code and press </> button in the top menu:

I can not get your </> formatting or

  • your ~~~ to work. I have a MAC…

Please ignore/delete all previous messages and just let me know how to get the SendUptime to work. Do I need to get a PC and an ANDROID to get this to work?

Thanks in advance
Krys

I edited your post this time, but you need to figure out how to post code on our forum. Otherwise your posts will be ignored and later deleted. Sorry, there are not many rules here. But this is the rule you need to follow.

BTW, I’m also on Mac. And the button you need is in under ESC

Send up time is just an example of using SimpleTimer for events that need to be run with some period.

Do you have a widget in the app which is connected to the virtual pin V5?
If not - put a Value Display and set it up for V5.

Also - always start simple. Just use our example and see if it works. When it works - combine it with your code.

Thanks Pavel. Please find enclosed cleaned code. Still can to get the “sendUtime delay” to work properly. Just does not change. I have a reading on the App that displays Virtual pin 5 and a graph that displays AnalogPins 0 and 1 through virtual pins 1 and 2.
I want to avoid too much data.
I am also recording the UnixTime and the VWC values on the SD card and is working fine but the Arduino/CC3000 often disconnect and reconnect fine but sometimes they just hang and I need to restart the Arduino and the App.

Here is the code within the ~~~ and also </>.

Appreciate your help.

    ~~~
/*
  SD card datalogger with internet NTP time updated every 24hrs.

 This example shows how to log data from three analog sensors
 to an SD card using the SD library.

 The circuit:
 * analog sensors on analog ins 0, 1, and 2
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 */
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10  //10 for WiFi, 4 for SD//
#define BLYNK_PRINT Serial // #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
//#define BLYNK_DEBUG // Optional, this enables lots of prints
#define WLAN_SSID "JHLW"
#define WLAN_PASS "ZbyszZdzislaw"
#define WLAN_SECURITY WLAN_SEC_WPA2
char auth[] = "2ac207956d4140e8b17ddda8f4438b27"; //

#include <SPI.h>
#include <SD.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <Time.h>
#include <BlynkSimpleCC3000.h>
#include <WidgetSD.h>
#include <SimpleTimer.h>

//Required for NTP time to be updated every 24hrs for SD logger
Adafruit_CC3000_Client client;
const unsigned long
connectTimeout  = 15L * 1000L, // Max time to wait for server connection
responseTimeout = 15L * 1000L; // Max time to wait for data from server
int
countdown       = 0;  // loop() iterations until next time server query
unsigned long
lastPolledTime  = 0L, // Last value retrieved from time server
sketchTime      = 0L; // CPU milliseconds since last server query

/*
//Attempt at having Sleep power save to create delay.

#define SERVER_IP              045, 055, 195, 102    // Logging server IP address.  Note that this
                                                   // should be separated with commas and NOT periods!
#define SERVER_PORT            8442               // Logging server listening port.

#define MAX_SLEEP_ITERATIONS   LOGGING_FREQ_SECONDS / 8  // Number of times to sleep (for 8 seconds) before
                                                         // a sensor reading is taken and sent to the server.
                                                         // Don't change this unless you also change the
                                                         // watchdog timer configuration.

 // Heartbeat period in seconds.
#define BLYNK_HEARTBEAT      60// default 10
// Internal state used by the sketch.
//Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT);
int sleepIterations = 0;
uint32_t ip;
volatile bool watchdogActivated = false;

// Define watchdog timer interrupt.
ISR(WDT_vect)
{
  // Set the watchdog activated flag.
  // Note that you shouldn't do much work inside an interrupt handler.
  watchdogActivated = true;
}
*/

WidgetSD sd;
BLYNK_ATTACH_WIDGET(sd, 1);

int chipSelect = 10;  //4 for SD

// Setup a function to be called every second  for sendUptime that does NOT work
SimpleTimer timer;

const int sensorsConnected = 2;  //number of sensors

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  Blynk.begin(auth, "JHLW", "ZbyszZdzislaw", WLAN_SEC_WPA2);  // Here your Arduino connects to the Blynk Cloud.
#define BLYNK_DEBUG // Optional, this enables lots of prints

  // Setup a function to be called every second
  timer.setInterval(1000L, sendUptime);


  //Script to confirm Arduino/CC3000 working.
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.print("Initializing SD card...");
  // see if the card is present and can be initialized:
  if (!SD.begin(4)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  //WiFi connect
  Serial.println(F("Hello, CC3000!\n"));
  displayDriverMode();
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!cc3000.begin()) {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    for (;;);
  }
  uint16_t firmware = checkFirmwareVersion();
  if (firmware < 0x113) {
    Serial.println(F("Wrong firmware version!"));
    for (;;);
  }
  displayMACAddress();
}

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.  NOT WORKING TRIED for 60secs
void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(5, (millis() / 60000) );
}

void loop()  {
  Blynk.run(); // All the Blynk Magic happens here...
  timer.run(); // Initiates SimpleTimer

  // To reduce load on NTP servers, time is polled once per roughly 24 hour period.
  // Otherwise use millis() to estimate time since last query.  Plenty accurate.
  if (countdown == 0) {           // Time's up?
    unsigned long t  = getTime(); // Query time server
    if (t) {                      // Success?
      lastPolledTime = t;         // Save time
      sketchTime     = millis();  // Save sketch time of last valid time query
      countdown      = 24 * 60 * 4 - 1; // Reset counter: 24 hours * 15-second intervals
    }
  } else {
    countdown--;                  // Don't poll; use math to figure current time
  }

  //Read sensor data and prepare for Blynking and sending to SD card.
  unsigned long currentTime = lastPolledTime + (millis() - sketchTime) / 1000;

  // make a string for assembling the data to log:
  String dataString = "";
  dataString += String(currentTime);
  dataString += ",";
  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < (sensorsConnected); analogPin++) {
    float sensorValue = analogRead(analogPin);
    float volt = (sensorValue / 1024.0) * 5.00 * 1.01 ; //Ref 5V
    int  VWC = 0;
    //Volumetric Water Content is a piecewise function of the voltage from the sensor
    if (volt < 0.00001 ) {
      VWC = 0;
    }
    else if (volt < 1.1) {
      VWC = (10 * volt) - 1;
    }
    else if (volt < 1.3) {
      VWC = (25 * volt) - 17.5;
    }
    else if (volt < 1.82) {
      VWC = (48.08 * volt) - 47.5;
    }
    else if (volt < 2.2) {
      VWC = (26.32 * volt) - 7.89;
    }
    else {
      VWC = (62.5 * volt) - 87.5;
    }

    dataString += String(VWC);
    if (analogPin < (sensorsConnected - 1)) {
      dataString += "%,";
    }
    else if (analogPin < (sensorsConnected)) {
      dataString += "%";
    }
    Blynk.virtualWrite(1, VWC);
    Blynk.virtualWrite(2, VWC);
    Blynk.virtualWrite(3, volt);
    Blynk.virtualWrite(7, millis() / 60000);
  }
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.csv", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.csv");
  }
  //delay(15000L);// Delay tried for delaying sendUptime but cc3000 times out and
  //Blynk app stops working
}
//
//Scripts below provide MACROS for checking state of HARDWARE.
//
//
//-------------------------------------------------------------------------/
/*!
    @brief  Displays the driver mode (tiny of normal), and the buffer
            size if tiny mode is not being used

    @note   The buffer size and driver mode are defined in cc3000_common.h
*/
//-------------------------------------------------------------------------/
void displayDriverMode(void)
{
#ifdef CC3000_TINY_DRIVER
  Serial.println(F("CC3000 is configure in 'Tiny' mode"));
#else
  Serial.print(F("RX Buffer : "));
  Serial.print(CC3000_RX_BUFFER_SIZE);
  Serial.println(F(" bytes"));
  Serial.print(F("TX Buffer : "));
  Serial.print(CC3000_TX_BUFFER_SIZE);
  Serial.println(F(" bytes"));
#endif
}
//-------------------------------------------------------------------------/
/*!
    @brief  Tries to read the CC3000's internal firmware patch ID
*/
//-------------------------------------------------------------------------/
uint16_t checkFirmwareVersion(void)
{
  uint8_t major, minor;
  uint16_t version;
#ifndef CC3000_TINY_DRIVER
  if (!cc3000.getFirmwareVersion(&major, &minor))
  {
    Serial.println(F("Unable to retrieve the firmware version!\r\n"));
    version = 0;
  }
  else
  {
    Serial.print(F("Firmware V. : "));
    Serial.print(major); Serial.print(F(".")); Serial.println(minor);
    version = major; version <<= 8; version |= minor;
  }
#endif
  return version;
}
//-------------------------------------------------------------------------/
/*!
    @brief  Tries to read the 6-byte MAC address of the CC3000 module
*/
//-------------------------------------------------------------------------/
void displayMACAddress(void)
{
  uint8_t macAddress[6];
  if (!cc3000.getMacAddress(macAddress))
  {
    Serial.println(F("Unable to retrieve MAC Address!\r\n"));
  }
  else
  {
    Serial.print(F("MAC Address : "));
    cc3000.printHex((byte*)&macAddress, 6);
  }
}
//-------------------------------------------------------------------------/
/*!
    @brief  Tries to read the IP address and other connection details
*/
//-------------------------------------------------------------------------/
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;

  if (!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}
// Minimalist time server query; adapted from Adafruit Gutenbird sketch,
// which in turn has roots in Arduino UdpNTPClient tutorial.
unsigned long getTime(void) {
  uint8_t       buf[48];
  unsigned long ip, startTime, t = 0L;
  Serial.print(F("Locating time server..."));
  // Hostname to IP lookup; use NTP pool (rotates through servers)
  if (cc3000.getHostByName("pool.ntp.org", &ip)) {
    static const char PROGMEM
    timeReqA[] = { 227,  0,  6, 236 },
                 timeReqB[] = {  49, 78, 49,  52 };
    Serial.println(F("\r\nAttempting connection..."));
    startTime = millis();
    do {
      client = cc3000.connectUDP(ip, 123);
    } while ((!client.connected()) &&
             ((millis() - startTime) < connectTimeout));
    if (client.connected()) {
      Serial.print(F("connected!\r\nIssuing request..."));
      // Assemble and issue request packet
      memset(buf, 0, sizeof(buf));
      memcpy_P( buf    , timeReqA, sizeof(timeReqA));
      memcpy_P(&buf[12], timeReqB, sizeof(timeReqB));
      client.write(buf, sizeof(buf));
      Serial.print(F("\r\nAwaiting response..."));
      memset(buf, 0, sizeof(buf));
      startTime = millis();
      while ((!client.available()) &&
             ((millis() - startTime) < responseTimeout));
      if (client.available()) {
        client.read(buf, sizeof(buf));
        t = (((unsigned long)buf[40] << 24) |
             ((unsigned long)buf[41] << 16) |
             ((unsigned long)buf[42] <<  8) |
             (unsigned long)buf[43]) - 2208988800UL;
        Serial.print(F("OK\r\n"));
      }
      client.close();
    }
  }
  if (!t) Serial.println(F("error"));
  return t;
}
//Attempted script to display time in Human Time but decided against a changing from LONG time to other time loses accuracy.
void digitalClockDisplay() {
  // digital clock display of the time
  printHrs(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}
void printHrs(int digits) {
  // utility for digital clock display: prints preceding colon and leading 0
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
void printDigits(int digits) {
  // utility for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
// This function is used by Blynk to receive data
size_t BlynkStreamRead(void* buf, size_t len)
{
  return Serial.readBytes((byte*)buf, len);
}
// This function is used by Blynk to send data
size_t BlynkStreamWrite(const void* buf, size_t len)
{
  return Serial.write((byte*)buf, len);
}
~~~

Did the code come OK this time (Wrapped)?

I already edited it in your first post. No need to post it twice.

Did you see my previous reply. Have you tried with a simple code? I just checked the example sketch and it’s working.

Thanks Pavel.

But I can not get it work. Must be doing something wrong in order not to be able to change the sampling time!!
The sketch is the one I send. The App (IOS 9.0.2) pointing to my Arduino Mega all it has are two widgets. The first reads V5 through a Value Display called Push(have tried other names too) in Push mode.
The second is a Graph in push mode too. (see pictures).

Please confirm that 60000 is the value I need to change (say to 600000 for 10 mins sampling in Blynk.virtualWrite(5, (millis() / 60000) ):wink:

Will try simplifying as you suggest but don’t understand why it works for you and not for me??

. Feel issues is either IOS (most likely) or cc3000 incompatible with sendUptime??

Also I am very interested in "Historical Graph” as this would solve me many issues. When will this become available in IOS?

Kind Rgds

Krys

The last photo Shows that Historical Graph not available in IOS

Hello Pavel
The sendUptime trick does NOT work at all. Even when I use your simple sketch.
I see on my phone the V5 (virtual pin 5) being updated every whatever I set… but the PRINCIPAL PARAMETER being measured just carries on at the sampling rate of the Arduino. Something is terribly wrong with the instructions on how to tie up the PUSH to the sendUptime. There must be a better way… please…

Do you have another sketch where it works!!??

Also whenever I blink.run() the whole process hangs after a few minutes and the cc3000 has to re-initialize. When I do not blink the sketch runs for hours on never hanging.

Looks like I have to return to my SD card as my measurement with a delay of 600 secs and use the Blynk as an instantaneous measurement until you can produce the “Historical Graphs” on the iPhone. Will try with Plotly or AmazonAWS.

Any other ideas??

Regards

Krys

Pavel
Eureka. Got it.
I was only writing the V5 data within the sendUptime loop. I though that the other BlynkWriteVirtual had to be outside of that Macro.

I am glad I insisted even though I was close to give up. You should probably clarify the above “stupid” issue…

Thanks for your help and patience.

When will the Historical Graphs (SD) become available for IOS.

1 Like