updating emoncms, new arduino sketch

I just updated to the latest emoncms (last time I installed was over a year ago), and things look a little different. It seems I have to update my arduino sketch.

I'm using and arduino with an ethernet shield. I'm trying to send just a temperature reading, using the following function and it isn't working:

[code]

void sendData(float temperature) {

  client.connect(server, 80);
  delay(1000);
 
  if (client.connected() ) {
    Serial.println("Connected");
   
    // send the HTTP GET request:   
    client.print("GET /emoncms/input/post.json?json={Temperature:");
    client.print(temperature);
    client.print("}&apikey=");
    client.print(apikey);   
    client.println(" HTTP/1.1");

  }//if(client.connect(server, 80)
  else {
    // if you couldn't make a connection:
    Serial.println("Connection failed");
    Serial.println("Disconnecting...");
    client.stop();
  }//else
  delay(2000);
}//sendData

[/code]

What adjustments do I need to make? BTW apikey is a global String variable that contains my apikey.

Robert Wall's picture

Re: updating emoncms, new arduino sketch

There should be absolutely no reason to change the sketch in your Arduino. Can you send the the same string from your browser, and is it accepted then? (It prints ok in the browser). If no, the problem is your emoncms installation.

[server IP or name]/emoncms/input/post.json?json={Temperature:[temperature]}&apikey=[apikey]

replacing the [terms in square brackets] with the correct values for you.

 

Kent88's picture

Re: updating emoncms, new arduino sketch

I copy-pasted that right into the browser address bar, substituting the values where you say to, and the response was "ok". Still no luck with the arduino with that sketch sending the data, though. You think it is an installation problem? How could I find out where I might have goofed?

 

edit: Went into my emoncms server's apache access.log file, and for entires related to my arduino I'm getting lines like this: 

[ipaddress and timestamp omitted] GET /emoncms/input/post.json?json={Temperature:10}apikey=[apikey omitted] HTTP/1.1 408 508 "-" "Arduino-ethernet"

BTW, I added this line to the sketch after println(" HTTP/1.1"); 

client.println("User-Agent: Arduino-ethernet");

Robert Wall's picture

Re: updating emoncms, new arduino sketch

The Apache log indicates that it is indeed the emonCMS installation that is at fault. What OS is it? Was it a fresh install to a different place or did you install over the top of the old version? Is the browser physically on the same machine as emonCMS? If it is and as the browser is responding, it looks like a permissions or addressing problem. Is your .htaccess file correct?

Kent88's picture

Re: updating emoncms, new arduino sketch

emoncms is a fresh install running on Raspbian. I'm not sure I understand what you are asking about the browser physically being on the same machine as emoncms. The above line from the log is showing the result of my sketch on the arduino attempting to send data to emoncms. All the attempts I've had at adding data via a browser (chome, specifically) have been from other computers not running emoncms, and they've been successful when I have the correct address and apikey. I have not altered any ".htaccess" file, where might I find that?

Robert Wall's picture

Re: updating emoncms, new arduino sketch

You had not said anything about your installation, so I had no means of knowing if you were running on an RPi, LAMP, MAMP, WAMP, a NAS, another Linux server or on your firms's or a rented server, or indeed something else.

Under WAMP, the server is visible within the machine: running a browser and using the command above shows emonCMS is running, but until you put the server "on-line" it is not visible outside the machine. That was a real possibility.

I'm no networking expert, however if you look up the Apache errors, it looks to me as if the server is timing out (408 - HTTP_REQUEST_TIME_OUT) and there is a problem with a loop (508 - HTTP_LOOP_DETECTED). It's quite likely that the loop is causing the timeout.

.htaccess is a hidden file, there is potentially one for every web-facing directory. It should have been copied with the installation, but if you manually copied files, it could be missing as it's hidden. However, as browsers on connected machine work, that's unlikely to be the problem.

I don't have a RPi so you need someone else to pick this up to help you further.

pb66's picture

Re: updating emoncms, new arduino sketch

Some more info would help, your 1st post says "updated emoncms" and your last post says "fresh install on raspbian" can you expand a little.

What version of emoncms did you upgrade from?

Did the sketch work ok prior to updating?

Did you update or did you start a fresh install?

What method did you use git or deb package?

Did you follow a specific guide?

Did you carry over any files/folders or make any other changes?

A fresh install on a Pi is normally quite a straight forward affair as it is so tried and tested, the questions are to establish what you should have and help to work out what could be different. 

Kent88's picture

Re: updating emoncms, new arduino sketch

Sorry for the confusion, I guess I should have said "fresh install", to me it is an upgrade, because I was running a version over a year old. To everyone else here, it might as well be a fresh install, though.

I used these instructions, with git: http://emoncms.org/site/docs/installlinux  I did everything in the tutorial up until (and including) the making a copy of settings.php, as is. I made a new mysql user who only has authority over the emoncms database and used those credentials. After that I downloaded the modules but haven't messed with them further. I overlooked the part about the file suhosin.ini, but I can't find that file anyway. I didn't enable multi-lingual support, and I did modify the entry for the timezone.

The sketch I posted earlier never worked, I didn't post the old one, that one printed to the client something like "GET /emoncms3/api/post.json?apikey=[apikey omitted, etc]" and I doubted it would work at all.

pb66's picture

Re: updating emoncms, new arduino sketch

Ok I guess a little more clarification is needed as both Robert and I have referred to the RaspberryPi and you have not corrected us and yet you are using the linux installation instructions. So what platform are you using?

What OS are you using ? "running on Raspbian" suggested a Pi running stock OS, but your comment about "suhosin.ini" questions that because that step is only applicable to Debian6.

The sketch I posted earlier never worked, I didn't post the old one, that one printed to the client something like "GET /emoncms3/api/post.json?apikey=[apikey omitted, etc]" and I doubted it would work at all.

Does this mean neither sketch ever worked or that the previous sketch worked with the previous emoncms?

Having had quick scan through the Linux guide, I can't see anything obvious that won't work on a Pi at first glance so it maybe that the install is good and a change can be made in the sketch since manually posting works ok.

If you can clarify the points above we will know what you should have and go from there.  

 

Kent88's picture

Re: updating emoncms, new arduino sketch

The emoncms server is running on Raspbian on a Raspberry Pi, are there special instructions for this platform? I was using the instructions provided on the link I gave above.

I had a sketch successfully running on the old emoncms install, that was the line you quoted, pb66, maybe I shouldn't have even posted it. When I said "the sketch I posted earlier" it was referring to the code in this original, thread-creating post.

pb66's picture

Re: updating emoncms, new arduino sketch

There are several installation guides specifically for the raspberry pi, The recommendation is to install emoncms to a raspberrypi running raspbian on a spinning hardrive using the debian package manager (apt-get).

I have looked a some of your old threads to try and get an insight to your system and establish if you had a hdd, as of dec2012 you were running emoncms on a virtual debian machine, so does mean this is a fresh install to a new platform ?

Either way do you have or intend to use a hdd ? the continuous writing of data by emoncms can dramatically shorten the lifespan of an sdcard, causing failures and loss of data.

I also noticed from your previous threads that getting your original sketch to work correctly has been the focus of previous discussions, so my advice would be to put the sketch aside for the moment and focus on your emoncms first.

The linux instructions you followed may work but with the aim of ensuring you have an easily maintained "stock" install that is tried and tested,  I would probably recommend starting afresh (assuming this is an entirely new Pi install and no data will be lost) 

When you have a working raspbian image, Installing emoncms to a pi can be done in a couple of commands using apt-get  https://github.com/Dave-McCraw/pkg-emoncms/blob/master/docs/install.md or for a full step by step guide to installing emoncms and a hdd (highly recommended) http://openenergymonitor.org/emon/node/5092. (these guides are quite new and have not yet made the documentation site).

You can still use the git method if you have strong reason to but that isn't recommended if you have option to use apt-get. instructions can be found in the "Raspberry Pi" section on emoncms.org documentation

Additionally the git methods are harder to update and leave too much open to variation, If you use the recommended Pi w/hdd via deb method it takes away a lot of uncertainty and you can confidently focus on your sketch knowing emoncms is sound.

Paul

Kent88's picture

Re: updating emoncms, new arduino sketch

I'd rather not use an hdd at this time. I have an 8GB SD card that I don't care about too much. Its still fairly new. What can I do to extend the life of it while using it as storage for emoncms data? Maybe only send data to it once every 15-30 minutes? I'm going to clean off the current raspbian image and put another one on there and start fresh using the install instructions for raspbian using apt-get.

In a few months after I decide if I'm happy with emoncms for this particular situation I plan to revisit the idea of using an hdd. Would I just need to modify my mysql install? Or would the entire OS have to be on the hdd? Where can I find instructions for this?

Robert Wall's picture

Re: updating emoncms, new arduino sketch

If you review the comments about the life of SD cards, then when writing at the normal rate, you will see that it might well not keep working for the couple of months you want. Sending data less frequently will obviously help. I think Paul gave you a link to the install instructions above. They start: "The easiest way is to put the image on BOTH the sd and the hdd, boot up on the sd and then edit the hdd to prepare it to boot to...."  The general idea is to boot from the SD card and run on the OS on the HDD.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.