Auto run between certain hours if nothing is pressed


i have been working on sketch arduino yun, new arduino, sketch supposed run if send 192.168.1.250/arduino/spinner , supposed run every 15 minutes if command isn't sent between 9am-6pm. have been able individual parts run fine, can run motor every 15 minutes between proper hours, or run motor every 15 minutes , reset timer when send above command,   but when combined of elements stops working. hoping take , point mo going wrong


// http://www.arduino.cc/en/tutorial/timecheck
#include <bridge.h>
#include <bridgeserver.h>
#include <bridgeclient.h>
#include <wire.h>
#include <adafruit_motorshield.h>
#include "utility/adafruit_ms_pwmservodriver.h"
adafruit_motorshield afms = adafruit_motorshield();
adafruit_dcmotor *mymotor1 = afms.getmotor(1);
#include <process.h>
#include <rbd_timer.h>

rbd::timer timer;
bridgeserver server;

process date;                 // process used date
int hours, minutes, seconds;  // results
int lastsecond = -1;          // need impossible value comparison

void setup() {
  bridge.begin();        // initialize bridge
  serialusb.begin(57600);    // initialize serial

  server.begin();
 
  afms.begin();
  mymotor1->setspeed(150);
  mymotor1->run(forward);
  mymotor1->run(release);

  timer.settimeout(60000); // rerun after time no input
  timer.restart();    //start timer
 
  while (!serial);              // wait serial monitor open
  serialusb.println("time check");  // title of sketch

  // run initial date process. should return:
  // hh:mm:ss :
  if (!date.running()) {
    date.begin("date");
    date.addparameter("+%t");
    date.run();
  }
}

void loop() {

  bridgeclient client = server.accept();
 
  // client exists?
  if (client) {
    // lets process request!
    process(client);
    client.stop();
  }
 
  if (lastsecond != seconds) { // if second has passed
    // print time:
 

    // restart date process:
    if (!date.running()) {
      date.begin("date");
      date.addparameter("+%t");
      date.run();
    }
  }

  //if there's result date process, parse it:
  while (date.available() > 0) {
    // result of date process (should hh:mm:ss):
    string timestring = date.readstring();

    // find colons:
    int firstcolon = timestring.indexof(":");
    int secondcolon = timestring.lastindexof(":");

    // substrings hour, minute second:
    string hourstring = timestring.substring(0, firstcolon);
    string minstring = timestring.substring(firstcolon + 1, secondcolon);
    string secstring = timestring.substring(secondcolon + 1);

    // convert ints,saving previous second:
    hours = hourstring.toint();
    minutes = minstring.toint();
    lastsecond = seconds;          // save time comparison
    seconds = secstring.toint();
  }
 
if (hours >= 9 && hours < 18){

  if(timer.onrestart()) {       
serialusb.println("yes");
}
}
 else {
  serialusb.println("no");
}
}

void process(bridgeclient client) {
  // collect user commands
  string command = client.readstringuntil('\\'); // load whole string

  command.trim();
  // check user entered ...
 
  // turn on
  if (command == "spinner") {
    serialusb.println("spinning");
      mymotor1->run(forward);
      mymotor1->setspeed(255); 
      delay(500);
     
      mymotor1->run(release);
      delay(500);
     
     
  }
 
}

welcome forum!   

it makes code easier read if use code tags </>

code: [select]
like this

what "doesnt work" code?   an exact description of behavior of code compared want lots.

does respond web command properly?

does continually print "yes" or "no" serial port depending on time of day?  "no" printed more "yes"?












Arduino Forum > Topics > Home Automation and Networked Objects > Auto run between certain hours if nothing is pressed


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'