Tim
Published © CERN-OHL

AquaFeeder 2.0: Automatic Fish Feeder

A fully automated fish feeder based on the Intel Edison, that cares for your fish and keeps you updated via WiFi!

IntermediateFull instructions provided6,299
AquaFeeder 2.0: Automatic Fish Feeder

Things used in this project

Hardware components

Servos (Tower Pro MG996R)
×2
Perma-Proto Breadboard Half Size
Perma-Proto Breadboard Half Size
×1

Software apps and online services

Arduino IDE
Arduino IDE
putty

Story

Read more

Schematics

AquaFeeder 2.0 Design

A simple diagram I made before setting out to create AF2.0. Will help you understand the design and function of the stand.

Circuit without LCD.

Complete circuit.

The fritzing diagram shows the entire circuit, along with the LCD and the servo motors.

Code

Code snippet #1

Plain text
Configuration file for intel edison. See step 12.
src/gz all http://repo.opkg.net/edison/repo/all
src/gz edison http://repo.opkg.net/edison/repo/all
src/gz core2-32 http://repo.opkg.net/edison/repo/all

Code snippet #2

Plain text
Editing wifi network information in the code.
//WiFI variablesint status = WL_IDLE_STATUS;
char ssid[] = "your network name";        //your network SSID (name)
char pass[] = "your*network*pass****";       // your network password
WiFiServer server(88);

AquaFeeder2.ino

Arduino
This is the main part of the sketch.
//#include <Wire.h>
#include <LiquidCrystal.h>
#include <Time.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include "textreader.c"
#include <SoftwareServo.h>
//#include <Intel_Edison_BT_SPP.h>

LiquidCrystal lcd(6, 7, 8, 9, 10, 11);

SoftwareServo myservo1; //servo that drops food
SoftwareServo myservo2; //lid servo
byte pos, posx, cent;

int spin1 = 4;  //feed servo
int spin2 = 5;  //lid servo
int buzz = A4;

#define TXT_BUF_SZ   50
#define REQ_BUF_SZ   90
char txt_buf[TXT_BUF_SZ] = {0};  // buffer to save text to
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer

char * str;
char * str1;
byte commaindex[15];
String txtval[15];
String s = "";
String s1 = "";
String command = "";
String message = "";
String webmsg = "";

//WiFI variables
int status = WL_IDLE_STATUS;
char ssid[] = "mynetwork";        //your network SSID (name)
char pass[] = "mypassword";       // your network password
WiFiServer server(88);

//NTP variables...
unsigned int localPort = 2390;             // local port to listen for UDP packets
IPAddress timeServer(129, 6, 15, 28);      // time.nist.gov NTP server
const int NTP_PACKET_SIZE = 48;            // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[NTP_PACKET_SIZE];        //buffer to hold incoming and outgoing packets

WiFiUDP Udp;                    // A UDP instance to let us send and receive packets over UDP

//time variables...
//int nowtime[3] = {0, 0, 0}; // not used (??)
byte prevtime[3] = {0, 0, 0};
byte nexttime[3] = {12, 12, 12};
byte prevdate;

//system variables...
int e = 0;
boolean i = false;
unsigned long last;
boolean feednow = false;
long thiss;
//byte nooftimesfed2day = 0;
boolean fed1, fed2, notfed;

//user interface variables...
byte feedtime1[3];
byte feedtime2[3];

void setup() {
  pinMode(buzz, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  digitalWrite(spin1, LOW);
  digitalWrite(spin2, LOW);
  tone(buzz, 1000, 100);   //beep

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  lcd.begin(16, 2);
  lcd.print("AquaFeeder 2.0");
  lcd.setCursor(0, 1);
  //Fancy stuff...
  for (e = 0; e < 16; e++) {
    lcd.print("=");
    delay(50);
  }

  Serial.begin(9600);
  Serial.println("Start");

  wifibegin();
  server.begin();
  delay(500);
  printWifiStatus();

  Serial.println("getting time"); //Serial messages
  setSyncProvider(getNTPtime);
  Serial.println("hour: ");
  Serial.println(hour());
  Serial.println("minute: ");
  Serial.println(minute());
  Serial.println("sec: ");
  Serial.println(second());
  Serial.println("getting variables");

  getvarfrommem();
  getnexttime();
  checkiffed();
  Serial.print("Notfed: ");
  Serial.println(notfed);

  myservo1.attach(2);
  myservo2.attach(3);
  Serial.println("Servo positioning");
  digitalWrite(spin1, HIGH);
  for (pos = 150; pos < 180; pos++) {
    myservo1.write(pos);
    delay(20);
  }
  digitalWrite(spin1, LOW);
  digitalWrite(spin2, HIGH);
  for (posx = 130; posx < 180; pos++) {
    myservo2.write(180);
    delay(20);
  }
  digitalWrite(spin2, LOW);
}

void loop() {
  printserver();
  lcddisplay();
  if ( timecompare(hour(), minute(), second(), 0, 0, 0) == 0 ) {
    Serial.println("syncing time");
    setSyncProvider(getNTPtime);
  }
  if (feednow1() == true || feednow2() == true || feednow == true) {
    feednow = false;
    tone(buzz, 300, 40);
    feedthefish();
    makemessage();
    //    sendemail();
  }
  delay(100);   //stabilise stuff?
}

//getting usr AND SOME OTHER variables from
//a text file --> /home/root/arduino
void getvarfrommem() {
  str = readardFile();
  s = String(str);

  Serial.println(s);
  commaindex[0] = s.indexOf(',');
  txtval[0] = s.substring(0, commaindex[0]);
  Serial.println(txtval[0].toInt());
  for (int l = 1; l < 15; l++) {
    commaindex[l] = s.indexOf(',', commaindex[(l - 1)] + 1);
    txtval[l] = s.substring(commaindex[(l - 1)] + 1, commaindex[l]);

    Serial.println((txtval[l].toInt()));
  }
  feedtime1[0] = txtval[0].toInt();
  feedtime1[1] = txtval[1].toInt();
  feedtime1[2] = txtval[2].toInt();
  feedtime2[0] = txtval[3].toInt();
  feedtime2[1] = txtval[4].toInt();
  feedtime2[2] = txtval[5].toInt();

  prevtime[0] = byte(txtval[6].toInt());
  prevtime[1] = txtval[7].toInt();
  prevtime[2] = txtval[8].toInt();
  nexttime[0] = txtval[9].toInt();
  nexttime[1] = txtval[10].toInt();
  nexttime[2] = txtval[11].toInt();

  Serial.println(prevtime[0]);
  prevdate = txtval[12].toInt();
  fed1 = txtval[13].toInt();
  fed2 = txtval[14].toInt();
}

void updatevartomem() {
  command = "echo '";
  command += feedtime1[0];
  command += ",";
  command += feedtime1[1];
  command += ",";
  command += feedtime1[2];
  command += ",";
  command += feedtime2[0];
  command += ",";
  command += feedtime2[1];
  command += ",";
  command += feedtime2[2];
  command += ",";
  command += prevtime[0];
  command += ",";
  command += prevtime[1];
  command += ",";
  command += prevtime[2];
  command += ",";
  command += nexttime[0];
  command += ",";
  command += nexttime[1];
  command += ",";
  command += nexttime[2];
  command += ",";
  command += prevdate;
  command += ",";    //See? I SUCK at prgramming! Anyone has a better way to do this?
  command += fed1;   //Though programming is fun while listening to Pink Floyd
  command += ",";
  command += fed2;
  command += "' >> /home/root/arduino";
  Serial.println(command);

  system("rm /home/root/arduino");          //remove previous confg file
  system("nano /home/root/arduino");  //make it again (LOL i suck at prgmming (and speling))

  system(command.buffer);
}

void makemessage() {
  message = "Subject:  Aquafeeder\n\n";
  message += "Hello from AquaFeeder! \n Fish have just been fed successfully! \n";
  message += "\n Current time: ";
  message += String(hour());
  message += ":";
  message += String(minute());
  message += ":";
  message += String(second());
  message += "\n Date: ";
  message += String(day());
  message += " ";
  message += monthStr(month());
  message += "\n Time to feed next: ";
  message +=  String(nexttime[0]);
  message += ":";
  message +=  String(nexttime[1]);
  message += ":";
  message +=  String(nexttime[2]);
}
void sendemail() {
  system("rm /home/root/message.txt");  //remove previous message file
  system("nano /home/root/message.txt");// and replace with a fresh one
  Serial.println("Replaced test file");

  command += "echo '";
  command += message;
  command += "' >> /home/root/message.txt"; // fille message.txt with some precious data concerning the royal crown,
  //uh no, just our email.
  Serial.println("Added message");

  system(command.buffer);
  system("python /home/root/gmail.py"); // not working ??//run the python program whcih actually sends teha email ah crap i ahte typping
  delay(6000);
  Serial.println("Sent email");
}

//Server related stuff...
void printserver() {
  WiFiClient client = server.available();   // listen for incoming clients
  Serial.println("Listening for clients");

  if (client == true) {
    Serial.println("GOT CLIENT!");
    lcd.clear();
    lcd.print("Updating");
    lcd.setCursor(0, 1);
    lcd.print("Webpage...");
    thiss = millis();
    e = 0;
    String currentline = "";
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);

        if (req_index < (REQ_BUF_SZ - 1)) {
          HTTP_req[req_index] = c;          // save HTTP request character
          req_index++;
        }
        if (c == '\n') {
          if (currentline.length() == 0) {

            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Refresh: 60");  // refresh the page automatically every 5 sec
            client.println();

            if (StrContains(HTTP_req, "GET /h ") || StrContains(HTTP_req, "GET /index.htm")) {
              Serial.println("home page");
              client.print("<!DOCTYPE html>");
              client.print("<html>");
              client.print("<font size = 14><strong> AquaFeeder</strong> </font> <font size = 5>From the Intel Edison</font><br>");
              client.print("<font size = 5><br> <a href=\"/h\">HOME</a> &nbsp;&nbsp;&nbsp;&nbsp; ");
              client.print("<a href=\"settime.htm\">SetTimes</a></font><br><br>");
              client.print("<font size = 3>AquaFeeder is running OK. Here are the details. To change feeding times, click 'SetTimes' above.</font>");
              client.print("<br><br><font size = 3><strong> Current time: </strong>");
              client.print(String(printtime(hour())));
              client.print(":");
              client.print(String(printtime(minute())));
              client.print("<br> <strong>Previously fed at: </strong>");
              client.print(String(printtime(prevtime[0])));
              client.print(":");
              client.print(String(printtime(prevtime[1])));
              client.print("<br> <strong>Next time to feed: </strong>");
              client.print(String(printtime(nexttime[0])));
              client.print(":");
              client.print(String(printtime(nexttime[1])));
              client.print("<br><br><strong>Feedtime 1: </strong>");
              client.print(String(printtime(feedtime1[0])));
              client.print(":");
              client.print(String(printtime(feedtime1[1])));
              client.print("<br><strong>Feedtime 2: </strong>");
              client.print(String(printtime(feedtime2[0])));
              client.print(":");
              client.print(String(printtime(feedtime2[1])));
              client.print("<br></font><br><font size = 5>Click <a href=\"/H\">here</a> to feed <i>now!</i></font><br>");
              client.print("<br> <a href = \"off.htm\">Turn off Edison</a>");
            }
            else if (StrContains(HTTP_req, "GET /settime.htm")) {
              Serial.println("set page");
              str1 = readhtmFile();
              Serial.println(str1);
              client.write(str1);
              delay(1000);
            }
            else if (StrContains(HTTP_req, "GET /off.htm")) {
              Serial.println("Switching off");
              system("shutdown now");
            }

            if (StrContains(HTTP_req, "ajax_inputs")) {
              Serial.println("ajax inputs");
              if (GetText(txt_buf, TXT_BUF_SZ)) {
                Serial.println("\r\nReceived Text:");
                webmsg = txt_buf;
                Serial.println(webmsg);

                commaindex[0] = webmsg.indexOf(',');
                txtval[0] = webmsg.substring(0, commaindex[0]);
                Serial.println(txtval[0].toInt());
                for (int l = 1; l < 15; l++) {
                  txtval[l] = 0;
                }
                for (int l = 1; l < 4; l++) {
                  commaindex[l] = webmsg.indexOf(',', commaindex[(l - 1)] + 1);
                  txtval[l] = webmsg.substring(commaindex[(l - 1)] + 1, commaindex[l]);

                  Serial.println((txtval[l].toInt()));
                }
                feedtime1[0] = txtval[0].toInt();
                feedtime1[1] = txtval[1].toInt();
                feedtime1[2] = 0;
                feedtime2[0] = txtval[2].toInt();
                feedtime2[1] = txtval[3].toInt();
                feedtime2[2] = 0;
                Serial.println("updated feedtimes");
                for (e = 0; e < 3; e++) {
                  Serial.println(feedtime1[e]);
                  Serial.println(feedtime2[e]);
                }
                delay(1000);
                getnexttime();
                lcd.clear();
                lcd.print("Updated times");
                delay(300);
              }
            }
            req_index = 0;
            StrClear(HTTP_req, REQ_BUF_SZ);
            client.println();
            Serial.println("DONE lient printinin");

            delay(20);
            client.stop();
            Serial.println("client disconnected");

            break;
          }
          else {      // if you got a newline, then clear currentLine:
            currentline = "";
          }
        }
        else if (c != '\r') {    // if you got anything else but a carriage return character,
          currentline += c;      // add it to the end of the currentLine
        }
        if (currentline.endsWith("GET /H")) {
          Serial.println("got link message");              // GET /H turns the LED on
          tone(buzz, 100, 300);
          feednow = true;
        }
      }
      else {
        e += 1;
        Serial.println(e);
        if (e > 503) {  //maybe not required
          client.stop();
          Serial.println("client disconnected");
          Serial.println(currentline);
          break;
        }
      }
    }

    delay(700);
  }
}
boolean GetText(char *txt, int len) {
  boolean got_text = false;    // text received flag
  char *str_begin;             // pointer to start of text
  char *str_end;               // pointer to end of text
  int str_len = 0;
  int txt_index = 0;

  // get pointer to the beginning of the text
  str_begin = strstr(HTTP_req, "&txt=");
  if (str_begin != NULL) {
    str_begin = strstr(str_begin, "=");  // skip to the =
    str_begin += 1;                      // skip over the =
    str_end = strstr(str_begin, "&end");
    if (str_end != NULL) {
      str_end[0] = 0;  // terminate the string
      str_len = strlen(str_begin);

      // copy the string to the txt buffer and replace %20 with space ' '
      for (int i = 0; i < str_len; i++) {
        if (str_begin[i] != '%') {
          if (str_begin[i] == 0) {
            // end of string
            break;
          }
          else {
            txt[txt_index++] = str_begin[i];
            if (txt_index >= (len - 1)) {
              // keep the output string within bounds
              break;
            }
          }
        }
        else {
          // replace %20 with a space
          if ((str_begin[i + 1] == '2') && (str_begin[i + 2] == '0')) {
            txt[txt_index++] = ' ';
            i += 2;
            if (txt_index >= (len - 1)) {
              // keep the output string within bounds
              break;
            }
          }
        }
      }
      // terminate the string
      txt[txt_index] = 0;
      got_text = true;
    }
  }

  return got_text;
}
// sets every element of str to 0 (clears array)
void StrClear(char *str, char length) {
  for (int i = 0; i < length; i++) {
    str[i] = 0;
  }
}

// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind) {
  char found = 0;
  char index = 0;
  char len;

  len = strlen(str);

  if (strlen(sfind) > len) {
    return 0;
  }
  while (index < len) {
    if (str[index] == sfind[found]) {
      found++;
      if (strlen(sfind) == found) {
        return 1;
      }
    }
    else {
      found = 0;
    }
    index++;
  }

  return 0;
}


void lcddisplay() {
  if (millis() - last > 4000) {
    i = !i;
    if (i == true) {
      lcd.clear();
      lcd.print("Time: ");
      lcd.print(printtime(hour()));
      lcd.print(":");
      lcd.print(printtime(minute()));
      lcd.setCursor(0, 1);
      if (WiFi.status() == WL_DISCONNECTED || WiFi.status() == WL_CONNECT_FAILED) {
        lcd.print("Not Connected");
      }
      else {
        lcd.print(WiFi.localIP());
      }
      delay(100);
    }
    else if (i == false) {
      lcd.clear();
      lcd.print("Next: ");
      lcd.print(printtime(nexttime[0]));
      lcd.print(":");
      lcd.print(printtime(nexttime[1]));
      lcd.setCursor(0, 1);
      lcd.print("Prev: ");
      lcd.print(printtime(prevtime[0]));
      lcd.print(":");
      lcd.print(printtime(prevtime[1]));
      delay(100);
    }
    last = millis();
  }
}

String printtime(byte v) {
  static String vv = "";
  if (v < 10) {
    vv = "0";
    vv += v;
    return vv;
  }
  else {
    vv = "";
    vv += v;
    return vv;
  }
}
//WiFI and Ntp stuff...
void wifibegin() {
  e = 0;
  while ( status != WL_CONNECTED) {
    e++;
    Serial.println("Connecting");
    lcd.clear();
    lcd.print("Connecting to:");
    delay(1000);
    lcd.clear();
    lcd.print(String(ssid));
    lcd.setCursor(0, 1);

    status = WiFi.begin(ssid, pass);
    delay(2000);
    if (e > 3) {
      lcd.clear();
      lcd.print("Failed connecting");
      break;
    }
  }
  for (int u = 0; u < 16; u++) {
    lcd.print("=");
    delay(20);
  }
  lcd.clear();
  lcd.print("Connected!");
  delay(200);
  Udp.begin(localPort);
}
time_t getNTPtime() {
  lcd.clear();
  lcd.print("Getting time..");

  sendNTPpacket(timeServer);
  delay(1000);

  if ( Udp.parsePacket() ) {
    Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer

    //the timestamp starts at byte 40 of the received packet and is four bytes,
    // or two words, long. First, esxtract the two words:

    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
    // combine the four bytes (two words) into a long integer
    // this is NTP time (seconds since Jan 1 1900):
    unsigned long secsSince1900 = highWord << 16 | lowWord;

    const unsigned long seventyYears = 2208988800UL;
    unsigned long epoch = secsSince1900 - seventyYears;

    return epoch + 19800; //19800 in my case: multiply your timezone by 3600
  }
  lcd.clear();
  lcd.print("Success!");
  delay(500);
}
unsigned long sendNTPpacket(IPAddress & address) {
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;

  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer, NTP_PACKET_SIZE);
  Udp.endPacket();
}
void printWifiStatus() {
  lcd.clear();
  lcd.print("IP Address");
  lcd.setCursor(0, 1);
  lcd.print(WiFi.localIP());
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
  delay(1000);
}

void checkiffed() {
  if (day() > prevdate) {
    if (timecompare(hour(), minute(), second(), feedtime1[0], feedtime1[1], feedtime1[2]) == 2) {
      if (timecompare(prevtime[0], prevtime[1], prevtime[2], feedtime2[0], feedtime2[1], feedtime2[2]) == 2) {
        notfed = true;
      }
      else {
        notfed = false;
      }
    }
    else if ( (timecompare(hour(), minute(), second(), feedtime1[0], feedtime1[1], feedtime1[2]) == 1) && (timecompare(hour(), minute(), second(), feedtime2[0], feedtime2[1], feedtime2[2]) == 2)) {
      notfed == true;
    }
  }
  else if (day() == prevdate) {
    if (fed2 == false && timecompare(hour(), minute(), second(), feedtime2[0], feedtime2[1], feedtime2[2]) == 1) {
      notfed = true;
    }
    else {
      notfed = false;
    }
  }
}
void getnexttime() {
  //less
  if ( (timecompare(hour(), minute(), second(), feedtime1[0], feedtime1[1], feedtime1[2]) == 2) || (timecompare(hour(), minute(), second(), feedtime2[0], feedtime2[1], feedtime2[2]) == 1)) {
    nexttime[3] = feedtime1[3];
  }
  else {
    nexttime[3] = feedtime2[3];
  }
  Serial.println(nexttime[3]);

}
byte timecompare(int hour1, int minute1, int sec1, int hour2, int minute2, int sec2) {
  //0 = equal, 1= more, 2 = less
  if  (hour1 == hour2) {
    if (minute1 == minute2) {
      return 0;
    }
    else if (minute1 > minute2) {
      return 1;
    }
    else if (minute1 < minute2) {
      return 2;
    }
  }
  else if (hour1 > hour2) {
    return 1;
  }
  else if (hour1 < hour2) {
    return 2;
  }
}

void feedthefish() {
  //Figure out next time to feed...
  Serial.println("Feeding...");
  if (feednow1() == true) {
    nexttime[3] = feedtime2[3];
    fed1 = true;
  }
  else if (feednow2() == true) {
    nexttime[3] = feedtime1[3];
    fed2 = true;
  }
  openlid();
  putfood();
  closelid();

  //set prevtime (previously fed time) as the time now...
  prevtime[0] = hour();
  prevtime[1] = minute();
  prevtime[2] = second(); //delete later if not required
  prevdate = day();

  //set fed1 fed2 here again?? --waittt
  updatevartomem();
}

void putfood() {
  lcd.clear();
  lcd.print("Putting Food...");
  digitalWrite(spin1, HIGH);
  //food servo
  for ( pos = 177; pos > 46; pos--) {
    Serial.println("feeding srvo");
    Serial.println(pos);
    myservo1.write(pos);
    delay(10);
  }
  //shake a bit...
  myservo1.write(60);
  delay(300);
  myservo1.write(40);
  delay(300);
  myservo1.write(50);
  delay(300);
  myservo1.write(30);
  delay(300);

  for (pos = 40; pos < 180; pos++) {
    myservo1.write(pos);
    Serial.println(pos);
    delay(28);
  }
  digitalWrite(spin1, LOW);
  lcd.clear();
  lcd.print("DONE!");
  delay(1000);
}
void openlid() {
  lcd.clear();
  lcd.print("Opening Lid...");
  digitalWrite(spin2, HIGH);
  for (posx = 180; posx > 0; posx--)
  {
    myservo2.write(posx);      // tell servo to go to position in variable 'pos'
    delay(32);
  }
  digitalWrite(spin2, LOW);
  lcd.clear();
  lcd.print("Opened!");
  delay(500);
}
void closelid() {
  lcd.clear();
  lcd.print("Closing Lid.");
  digitalWrite(spin2, HIGH);
  for (posx = 1; posx < 180; posx++) {
    myservo2.write(posx);
    delay(30);
  }
  digitalWrite(spin2, LOW);
  lcd.clear();
  lcd.print("Closed Lid!");
}


boolean feednow1() {
  if ( (timecompare(hour(), minute(), second(), feedtime1[0], feedtime1[1], feedtime1[2]) == 0) && fed1 == false) {
    return true;
  }
  else {
    return false;
  }
}
boolean feednow2() {
  if ( (timecompare(hour(), minute(), second(), feedtime2[0], feedtime2[1], feedtime2[2]) == 0) && fed2 == false) {
    return true;
  }
  else {
    return false;
  }
}

textreader.c

Arduino
This code is responsible for reading the text file containing config information.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>

char* readardFile (){
  FILE *f = fopen("/home/root/arduino", "rb");
  if (f != NULL) {
    fseek(f, 0, SEEK_END);
    long pos = ftell(f);
    fseek(f, 0, SEEK_SET);
    char *bytes = (char*)malloc(pos);
    fread(bytes, pos, 1, f);
    fclose(f);
  
    return bytes;
  } else {
    return NULL; 
  }
}
char* readhtmFile (){
  FILE *f1 = fopen("/home/root/text.htm", "rb");
  if (f1 != NULL) {
    fseek(f1, 0, SEEK_END);
    long pos1 = ftell(f1);
    fseek(f1, 0, SEEK_SET);
    char *bytes1 = (char*)malloc(pos1);
    fread(bytes1, pos1, 1, f1);
    fclose(f1);
  
    return bytes1;
  } else {
    return NULL; 
  }
}

Credits

Tim

Tim

3 projects • 7 followers
I like electronics, Arduino in particular. I suck at programming (but i still try my luck at it). Other interests include music, particularly prog.

Comments