Arduino uno + ethernet shield

Hi

I am planing to put together a arduino + ethernet setup, with BMP085 and DHT22 so i can upload to Emoncms (own server).

 

Got the BMP085 and DHT22 running and giving out data on seriel (usb).

Now looking for a sketch to show how to put together the payload to send to the ethernet shield.

I had a look at the 03 - Basic Web Client

(https://github.com/openenergymonitor/NanodeRF/blob/master/Guide/c_BasicW...)

 

with no luck, Wrong ethernet card

 

So if any have a sketch for the arduino+shield i would like to have a look.

 

 

Kent88's picture

Re: Arduino uno + ethernet shield

Did you ever get this to work?

ageurtse's picture

Re: Arduino uno + ethernet shield

Hello,

 

This is how i did it with a arduino nano and en encj2860 and using the ethercard library.

I read 2 one wire thermometers and send them to my emoncms server

maybe you could use it.

 

// Demo using DHCP and DNS to perform a web client request.
// 2011-06-08 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
#include <EtherCard.h>
#include <OneWire.h>
#include <DallasTemperature.h>
char payload[50];

void(* resetFunc) (void) = 0; //declare reset function @ address 0

// ethernet interface mac address, must be unique on the LAN
// and other stuff used for the network interface
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x35 };
byte Ethernet::buffer[700];

char website[] PROGMEM = "xx.xx.xx.xx";//destination website
// This is the char array that holds the reply data
char line_buf[50];

// Stuff used for one wire sensors
// Data wire is plugged into pin 7 on the Arduino
#define ONE_WIRE_BUS 7

// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
  int temp1;
  int temp2;

// Some random stuff used in this program
static uint32_t timer;
byte wd_counter;

// called when the client request is complete
static void my_callback (byte status, word off, word len) {

  get_reply_data(off);
 
  if (strcmp((const char*) line_buf,"ok"))
  {
    wd_counter=0;
    Serial.println( F(" recieved ok."));
  } else
  {
    Serial.println( F(" !!! ERROR !!!."));
    Serial.println( F(">>>"));
    Serial.print((const char*) Ethernet::buffer+off);
    Serial.println( F("<<<"));
  }
}

//Setup the board
void setup () {

 
  //Start serial port
  Serial.begin(9600);
  Serial.println( F("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"));
  Serial.println( F("\nNANO EMONCMS Temperatuur sender\n\n\n"));
 
  //Start ethernet port
  if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0)
    Serial.println(  F("Failed to access Ethernet controller"));
  //Get own ip adress
  if (!ether.dhcpSetup())
    Serial.println( F("DHCP failed"));
  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip); 
  ether.printIp("DNS: ", ether.dnsip); 
  //Look ip destination website
  if (!ether.dnsLookup(website))
    Serial.println( F("DNS failed"));
  ether.printIp("SRV: ", ether.hisip);

  // Startup one wire sensors
  sensors.begin();
}

// Main program
void loop () {

  ether.packetLoop(ether.packetReceive());
 
  if (wd_counter>=10) {
    Serial.println( F("Resetting device"));
    resetFunc();
  }

 
 
  if (millis() > timer) {
    wd_counter++;
    timer = millis() + 25000;
    Serial.println(" ");
    Serial.print( F("Attempt number "));
    Serial.print(wd_counter);
    Serial.print( F(" of 10, data send to emoncms: "));
   
    sensors.requestTemperatures();
    //temp1 = round(sensors.getTempCByIndex(0)*10);
    //temp2 = round(sensors.getTempCByIndex(1)*10);     
    temp1 = sensors.getTempCByIndex(0)*10;
    temp2 = sensors.getTempCByIndex(1)*10;     
   
    sprintf(payload,"{Temp_buiten_camping:%d,Temp_binnen_camping:%d}",temp1,temp2);
    Serial.print(payload);
    ether.browseUrl(PSTR("/emoncms/input/post.json?apikey=********06d069745bfe8dac70040261&json="), payload, website, my_callback);

  }
}

int get_reply_data(word off)
{
  memset(line_buf,NULL,sizeof(line_buf));
  if (off != 0)
  {
    uint16_t pos = off;
    int line_num = 0;
    int line_pos = 0;
   
    // Skip over header until data part is found
    while (Ethernet::buffer[pos]) {
      if (Ethernet::buffer[pos-1]=='\n' && Ethernet::buffer[pos]=='\r') break;
      pos++;
    }
    pos+=2;
    while (Ethernet::buffer[pos])
    {
      if (line_pos<49) {line_buf[line_pos] = Ethernet::buffer[pos]; line_pos++;} else break;
      pos++;
    }
    line_buf[line_pos] = '\0';
    return line_pos;
  }
  return 0;
}

[Edit: APIkey obfuscated - RW]

Comment viewing options

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