Show Posts
Pages: [1] 2 3
1  Using Arduino / Networking, Protocols, and Devices / Upload to Pachube with min/max values for graphs on: January 05, 2012, 12:42:01 pm
Greetings,

till a while back a cvs upload would have been benefited from the opportunity to manually scale the graphs. Now they (pachube) removed this opportunity.

Can anyone post a code that will send to pachube the min/max values as well ?

Thanks and regards,
Marian
2  Using Arduino / Interfacing w/ Software on the Computer / Re: from Arduino to PC on: August 27, 2011, 08:14:27 pm
MikMo thank you very much.

When the motion sensor triggers I want the PC to run a small program with an argument (initiate video recording from one of the security cameras)

I will take a look at your link.

Thank you,
Marian
3  Using Arduino / Interfacing w/ Software on the Computer / from Arduino to PC on: August 27, 2011, 07:34:53 am
Greetings,

Here is my plan; Motion sensor (NC or NO) -> Arduino -> USB connection ->PC -> PC runs a small script and execute a command when motion sensor is triggered.

Do you guys have any example that will come close ?

Many thanks,
Marian
4  Using Arduino / Programming Questions / Re: leading zero for an integer on: February 25, 2011, 06:22:33 am
%02d works perfectly. Many thanks !

cheers,
Marian
5  Using Arduino / Programming Questions / leading zero for an integer on: February 25, 2011, 05:35:25 am
Greetings,
I am successfully uploading a 4 data streams to pachube, but today I just realized that using the below code a value of 8.06 is being uploaded as 8.6 ?? I believe I read somewhere that this is called padding. Can someone help me with a suggestion how to add padding to this code ? Many thanks.

Code:

int temp_Current1 = (temp_Current - (int)temp_Current)*100;
      int pH_val1 = (pH_val - (int)pH_val)*100;
     
      sprintf(pachube_data,"%0d.%d,%0d.%d,%d,%d,%d,%d",(int)temp_Current,abs(temp_Current1),(int)pH_val,abs(pH_val1),orp_val,orpSD_val, successes + 1, failures);
cheers, Marian
6  Using Arduino / Networking, Protocols, and Devices / Re: Use of ports. on: February 14, 2011, 10:09:51 pm
Ran, absolutely right. I know that the webserver can take any available port without any problem. What about pachube ? Can one use any port to feed ?

cheers,
Marian
7  Using Arduino / Networking, Protocols, and Devices / Re: Use of ports. on: February 14, 2011, 08:13:27 pm
Ran,

I have it behind a router with firewall (wrt54g/dd-wart firmware), but using it as webserver I have to port forward a port. Right ? There is no other way around I guess.

cheers,
Marian
8  Using Arduino / Networking, Protocols, and Devices / Re: Use of ports. on: February 14, 2011, 08:08:52 pm
Gentlemen, thank you very much for your support.
A bit about configuration: It's a reef tank controller that is uploading four datastreams to pachube. The webserver picks up four graphs from pachube and displays as webpage. This controller (Arduino Mega/wiznet5100), as a primary function, controls a lot of features of the tank, so stability is a main concern. So far, without latest pachube update it was rock solid for two years. Hope it will stay like this.
I am uploading to pachube once a minute (no reason for hammering) and I can go even slower since in a reef only bad things happen fast.
So far, with the server on port 81 and client on 80 it was stable for the last 12 hours.

Here are some fragments of the code;
Code:

#define SHARE_FEED_ID      xxxxx
#define UPDATE_INTERVAL  60000
#define RESET_INTERVAL    30000   
#define PACHUBE_API_KEY   "xxxxx"

....

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 123 };
byte remoteServer[] = { 173, 203, 98, 29  };            // pachube.com
Server server(81);
Client localClient(remoteServer, 80);
char pachube_data[128];


...

void pachube_in_out() {
  if (request_pause){
    if ((millis() - last_connect) > interval){
      ready_to_update = true;
      reading_pachube = false;
      request_pause = false;
      found_status_200 = false;
      found_session_id = false;
      found_CSV = false;
    }
  }
  // Serial.println ("Before ready to connect");
  if (ready_to_update){
    if (localClient.connect()) {
         
      int temp_Current1 = (temp_Current - (int)temp_Current)*100;
      int pH_val1 = (pH_val - (int)pH_val)*100;
     
      sprintf(pachube_data,"%0d.%d,%0d.%d,%d,%d,%d,%d",(int)temp_Current,abs(temp_Current1),(int)pH_val,abs(pH_val1),orp_val,orpSD_val, successes + 1, failures);
     
      localClient.print("PUT /api/");
      localClient.print(SHARE_FEED_ID);
      localClient.print(".csv HTTP/1.1\nHost: pachube.com\nX-PachubeApiKey: ");
      localClient.print(PACHUBE_API_KEY);
      localClient.print("\nContent-Type: text/csv\nContent-Length: ");
      localClient.print(strlen(pachube_data));
      localClient.print("\nConnection: close\n\n");
      localClient.print(pachube_data);
      localClient.print("\n");

      ready_to_update = false;
      reading_pachube = true;
      request_pause = false;
      interval = UPDATE_INTERVAL;

      delay(100);
    }
    else {   
      Serial.print("connection failed!");
      Serial.print(++failures);
      found_status_200 = false;
      found_session_id = false;
      found_CSV = false;
      ready_to_update = false;
      reading_pachube = false;
      request_pause = true;
      last_connect = millis();
      interval = RESET_INTERVAL;
      setupEthernet(interval);
    }
  }

  while (reading_pachube){
    while (localClient.available()) {
      checkForResponse();
    }

    if (!localClient.connected()) {
      disconnect_pachube();
    }
  }
}


I will keep you updated about stability,

cheers,
Marian


   
9  Using Arduino / Networking, Protocols, and Devices / Use of ports. on: February 14, 2011, 05:36:58 am
Hello,

I am trying hard to run a webserver and upload data to pachube at the same time. The code works for a while and freezes randomly.

I am trying to debug this situation and I came close to this statements:

byte ip[] = { 192, 168, 1, 123 };
byte remoteServer[] = { 209,40,205,190 };            // pachube.com
Server server(80);
Client localClient(remoteServer, 80);

Can a server and a client share the same port ?

many thanks,
Marian
10  Using Arduino / Programming Questions / Pachube upload on: February 13, 2011, 05:02:25 pm
Greetings gents,

Can anyone help with a simple sketch to upload data from four sensors to a pachube feed ?
 I have adapted the scrip that Jose Anes put together and it works for about one hour and after that freezes my Mega not only the feed. For the life of me I could not figure out for the last week what is going wrong. ... very frustrating.

Many thanks,
Marian

here is the only modification that I've done to Jose's script:

void collectSensorData () {
  assignSensorData (0, temp_Current, "Water temperature", "F");
  assignSensorData (1, pH_val, "pH value", "pH");
  assignSensorData (2, orp_val, "Reef ORP value ", "mV");
  assignSensorData (3, orpSD_val, "Sulfur denitrator ORP", "mV");
}

void assignSensorData (int i, double value, char * label, char * units) {
  sensorValues = value;
  sensorLabels = label;
  sensorUnits = units; 
}
11  Using Arduino / Programming Questions / Pachube upload using Tom's example on: February 08, 2011, 10:07:07 pm
Hello,

i was using Tom's (Igoe) example and it works well for integer feeds. So, I wonder how this code should be modified to accommodate float type feeds ? What about multiple feeds (ID 0, 1, 2, etc.)

Many thanks,
Marian

here is Tom's code:

/*
  Pachube sensor client
 
 This sketch connects an analog sensor to Pachube (http://www.pachube.com)
 using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
 the Adafruit Ethernet shield, either one will work, as long as it's got
 a Wiznet Ethernet module on board.
 
 Circuit:
 * Analog sensor attached to analog in 0
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 15 March 2010
 updated 4 Sep 2010
 by Tom Igoe
 
 http://www.tigoe.net/pcomp/code/category/arduinowiring/873
 This code is in the public domain.
 
 */

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

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// assign an IP address for the controller:
byte ip[] = {
  192,169,1,20 };
byte gateway[] = {
  192,168,1,1};
byte subnet[] = {
  255, 255, 255, 0 };

//  The address of the server you want to connect to (pachube.com):
byte server[] = {
  209,40,205,190 };

// initialize the library instance:
Client client(server, 80);

long lastConnectionTime = 0;        // last time you connected to the server, in milliseconds
boolean lastConnected = false;      // state of the connection last time through the main loop
const int postingInterval = 10000;  //delay between updates to Pachube.com

void setup() {
  // start the ethernet connection and serial port:
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  // give the ethernet module time to boot up:
  delay(1000);
}

void loop() {
  // read the analog sensor:
  int sensorReading = analogRead(A0);   

  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    sendData(sensorReading);
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}

// this method makes a HTTP connection to the server:
void sendData(int thisData) {
  // if there's a successful connection:
  if (client.connect()) {
    Serial.println("connecting...");
    // send the HTTP PUT request.
    // fill in your feed address here:
    client.print("PUT /api/YOUR_FEED_HERE.csv HTTP/1.1\n");
    client.print("Host: www.pachube.com\n");
    // fill in your Pachube API key here:
    client.print("X-PachubeApiKey: YOUR_KEY_HERE\n");
    client.print("Content-Length: ");

    // calculate the length of the sensor reading in bytes:
    int thisLength = getLength(thisData);
    client.println(thisLength, DEC);

    // last pieces of the HTTP PUT request:
    client.print("Content-Type: text/csv\n");
    client.println("Connection: close\n");

    // here's the actual content of the PUT request:
    client.println(thisData, DEC);

    // note the time that the connection was made:
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}


// This method calculates the number of digits in the
// sensor reading.  Since each digit of the ASCII decimal
// representation is a byte, the number of digits equals
// the number of bytes:

int getLength(int someValue) {
  // there's at least one byte:
  int digits = 1;
  // continually divide the value by ten,
  // adding one to the digit count for each
  // time you divide, until you're at 0:
  int dividend = someValue /10;
  while (dividend > 0) {
    dividend = dividend /10;
    digits++;
  }
  // return the number of digits:
  return digits;
}
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: sscanf - ignoring characters on: January 21, 2011, 07:05:42 pm
Paul,

my sincere regrets. Has been a long week smiley-wink
Yes I meant sscanf:

char inData_pH;
char string_pH[8];
sscanf(inData_pH, "%*3c %s", string_pH)  // i.e. from inData_pH ignore the 3 characters and assign rest to string_pH
pH_val = atof(string_pH);

13  Forum 2005-2010 (read only) / Syntax & Programs / sscanf - ignoring characters on: January 21, 2011, 05:57:13 pm
Hello,

obviousely I don't understand something:

I have a string : "pH=8.23" and I want to ignore the first three characters: "pH="

so I thought that :

char inData_pH;
char string_pH[8];
sstring(inData_pH, "%*3c %s", string_pH)  // i.e. from inData_pH ignore the 3 characters and assign rest to string_pH
pH_val = atof(string_pH);

can you guys help a bit ?

cheers,
Marian
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: modulo (%) operator results on: December 02, 2010, 08:46:16 am
Thank you Paul.

Here is the code I use:

client.println("<td align=center>"); client.print(ph_val / 100); client.println("."); client.print(ph_val % 100); client.println("</td>");

Can it be optimized ? ph_val is the value provided by the analog read.

cheers,
Marian
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: modulo (%) operator results on: December 02, 2010, 08:21:48 am
I have the pH value displayed on an LCD and on this I have a small if loop checking for fractional < 10 and if true print a leading zero since on the LCD I can control the position.

My problem is on the webpage where where I can not control the position. Paul can you please detail how whould you use the print instruction for this ?

Thank you,
Marian
Pages: [1] 2 3