login

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - yolco

Pages: [1]
1
Programming Questions / New line on file Issue
« on: February 08, 2012, 02:03:30 PM »
Hi,

I'm using an ethernet shield 05 on an arduino mega, and I have the nest issue, could someone help me with, please?

- I make a program with a web server which makes some measurements and write one by one in a file, so a client could read these values from a browser. But when I'm trying to write to a file continously, I mean: I opened a file, write on it, close it, and after a while, I repeat the operation. I want it adds lines, one after one. But even using the example, I could make it right. It always overwrite the file and only shows the last measurements done. How can I solve this?


#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

#define BUFSIZ 100

byte mac[] = { 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA };
byte ip[] = { 192,168,1, 2 };
byte gateway[] = {  192,168,1, 1 };
byte subnet[] = { 255, 255, 252, 0 };

Server server(80);

Sd2Card card;
SdVolume volume;
SdFile root, file;

void setup() {
  Serial.begin(9600);

  pinMode(53, OUTPUT);
  digitalWrite(53, HIGH);

 card.init(SPI_HALF_SPEED, 4);
 volume.init(&card);
 root.openRoot(&volume);

  Ethernet.begin(mac, ip);
  server.begin();
}

void loop() {
  ClientController();
  delay(10);
 
  PrintFile();
  delay(2000);
}

void PrintFile() {
  if (file.open(&root, "Probes.txt", FILE_WRITE)) {
    file.println("Trying to write several sentences...");
    file.close();
  }
}

void ClientController() {
  char clientline[BUFSIZ];
  int index = 0;

  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;
    index = 0;

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          if (index >= BUFSIZ)
            index = BUFSIZ -1;

          continue;
        }
        clientline[index] = 0;
        Serial.println(clientline);

        if (strstr(clientline, "GET / ") != 0) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          client.println("<h2>Files:</h2>");
          ListFiles(client, LS_SIZE);
        }
        else if (strstr(clientline, "GET /") != 0) {
          char *filename;

          filename = clientline + 5; // look after the "GET /" (5 chars)
          (strstr(clientline, " HTTP"))[0] = 0;
          Serial.println(filename);

          if (! (file.open(&root, filename, O_READ))) {
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html"); 
            client.println();
            client.println("<h2>File Not Found!</h2>");
            break;
          }

          Serial.println("Opened!");

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/plain");
          client.println();

          int16_t c;
          while ((c = file.read()) > 0) {
            client.print((char)c);
          }
          file.close();
        }
        else {
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>File Not Found!</h2>");
        }
        break;
      }
    }
    delay(1);
    client.stop();
  }
}

void ListFiles(Client client, uint8_t flags) {
  dir_t p;
 
  root.rewind();
  client.println("<ul>");
  while (root.readDir(p) > 0) {
    if (p.name[0] == DIR_NAME_FREE) break;
    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;
    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
 
    client.print("<li><a href=\"");
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name == ' ') continue;
      if ( i == 8 ) {
        client.print('.');
      }
      client.print(p.name);
    }
    client.print("\">");
 
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name == ' ') continue;
      if ( i == 8 ) {
        client.print('.');
      }
      client.print(p.name);
    }
 
    client.print("</a>");
 
    if (DIR_IS_SUBDIR(&p)) {
      client.print('/');
    }

    if (flags & LS_DATE) {
       root.printFatDate(p.lastWriteDate);
       client.print(' ');
       root.printFatTime(p.lastWriteTime);
    }
    if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {
      client.print(' ');
      client.print(p.fileSize);
    }
    client.println("</li>");
  }
  client.println("</ul>");
}
2
Wiring Hardware Questions / Re: Winsensor Gas Sensors
« on: January 27, 2012, 07:34:23 AM »
Hi,

first of all, thanks!!

I already have the connections done, and I'm reading values from the sensor.
But now my problem is how I can interpolate this values to have the real concentration measurement.

So, I need a mathematical formula to do this, because the manufacturer only give a graphic with general values.

Do you have some formulas to do these measurements??

Thanks again!!

Regards.
3
Website Questions / Re: MQ-135 Air Pollution Sensor
« on: January 25, 2012, 09:53:33 AM »
Hi,

I'm working with some sensor like this, but I don't know how to interpolate the graphics.

Could you help me with this please?? Which is the formula you used to print values??

Thanks!!

4
Wiring Hardware Questions / Winsensor Gas Sensors
« on: January 24, 2012, 04:24:35 AM »
Hi,

I'm developing an enviromental station and I bought some winsensor gas sensors, as MQ135, I'm trying to do right measurements, but first I don't know if I wire them correctly, also the values they give me are strange.

At the second issue, the values measured, I need to know how to convert it to a right ppm values, because I understand that my arduino give me the values between 0 and 1023.

Could anyone give me some help about??

Thanks!!
Pages: [1]