Show Posts
Pages: [1]
1  Community / Exhibition / Gallery / Re: Basic Analog Pin reporting using ENCENC28J60 EthernetShield on: May 26, 2011, 08:29:14 pm
Hey Bino,

Thanks for your post, but I'm trying to make a really simple example to show how to use the Arduino as a Client to post data to a database using PHP/MySQL leveraging your post by basically making it bare-bones.

I have run it trying to do a few things but I some Errors that I don't really know much about as I am not an full-fledge programmer.

I get one error:
  Invalid conversion from 'void(*)(uint8_t,uint16_t)' to 'void(*)(uint8_t,uint16_t,uint16_t)' when trying to compile.

So for fun, I added a blank uint16_t in the callback function, just to make it compile.  In anycase, when I upload to the Arduino, I can see that the HTTPCALL does function, but I have no idea whether I am actually connecting or sending data to my PHP script. (I check the db to see if it arrives, to no avail).

How can I make the below code work? What am I missing? Did I take out too much?

How can I see whether it is connecting to my PHP script?  Why did I get that error?

SO MANY QUESTIONS! hahah....

Anyway, your help and guidance would be greatly appreciated! 

CHEERS!

Code:
/*
WE USE MODIFIED VERSION OF Andy's Library ver 1.6
*/

#include <etherShield.h>

#include <string.h>


//----ETH VARS-------------------------------


#define PORT 80           // Ndak bisa di rubah

byte magic;
byte mac[6] = {0x54,0x55,0x58,0x10,0x00,0x25};
byte ip[4] = {192,168,1,203}; // ip of arduino
byte gw[4] = {192,168,1,245};  //ip of router
byte srv[4] = { 192,168,1,66 }; // ip of server
char host[13]="192.168.1.66";   // server name?
char callfile[21]="/ethernet_to_db.php?"  ;    // place to put crap
byte mymagic=0x0a;

int8_t dns_state=0;
uint32_t timetosend=millis();
uint16_t dat_p;
//long lastDnsRequest = 0L;
int plen = 0;

EtherShield es= EtherShield();

#define BUFFER_SIZE 550
uint8_t buf[BUFFER_SIZE+1];
//--------------------------------------------

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

 
  es.ES_enc28j60Init(mac);

  //init the ethernet/ip layer:
  es.ES_init_ip_arp_udp_tcp(mac, ip, PORT);
o a
  // init the web client:
  es.ES_client_set_gwip(gw);  // e.g internal IP of dsl router
  es.ES_client_set_wwwip(srv);
 
 
  timetosend = millis();
   
 
}


void loop()
{
  //Do this in any condition
  dns_state=2;
  // handle ping and wait for a tcp packet - calling this routine powers the sending and receiving of data
  // If we have IP address for server and its time then request data
  ethReady();
  //---------------------------


  if(millis() - timetosend > 1000)  // every 10 seconds
  {
    timetosend = millis();
 
    ethSend();
  }
}



void ethReady()
{
  plen=0;
  plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);
  dat_p=es.ES_packetloop_icmp_tcp(buf,plen);

}

void ethSend()
{
      char HTTPCALL[150];
      strcpy(HTTPCALL, "GET ");
      strcat(HTTPCALL, callfile);
      strcat(HTTPCALL, "value=HELLO");
        //strcat(HTTPCALL, nodeid);
        //strcat(HTTPCALL, "&");
      //strcat(HTTPCALL, "nodepin=");
        //strcat(HTTPCALL, nodepin);
       // strcat(HTTPCALL, "&");

      strcat(HTTPCALL, " HTTP/1.0\r\nHost: ");
      strcat(HTTPCALL, host);
      strcat(HTTPCALL, "\r\nUser-Agent: EtherShield/1.6\r\nAccept: text/html\r\nConnection: close\r\n\r\n");
      //-------END----Struct the HTTPCALL

      Serial.println("HTTP Data To Send");
     
      Serial.println(HTTPCALL);
     
      // note the use of PSTR - this puts the string into code space and is compulsory in this call
      // second parameter is a variable string to append to HTTPPATH, this string is NOT a PSTR
      //es.ES_client_browse_url(PSTR(HTTPPATH), NULL, PSTR(HOSTNAME), &browserresult_callback);
      //es.ES_client_browse_url(PSTR(HTTPPATH), strtimetosend, PSTR(HOSTNAME), &browserresult_callback);
      //es.ES_client_browse_url(PSTR(HTTPPATH), strtimetosend, PSTR(""), &browserresult_callback);

//The actual code to send data to PHP script:
      es.ES_client_browse_url(callfile, HTTPCALL, host, &browserresult_callback);
       
}

void browserresult_callback(uint8_t statuscode,uint16_t datapos){
  if (datapos != 0)
  {
   //removed since all was commented out anyway
   
  }
}



2  Topics / Home Automation and Networked Objects / Re: Arduino / WIZ811MJ troubles on: May 26, 2011, 04:15:35 pm
Did you get it to work?

I've been killing myself with the ENC28J60 and now that I've found the WIZ811MJ I'm about two minutes away from ordering, your wiring diagram is the key to make it easy after the crap the ENC28J60 put me through (mess libraries/code/comments).  Just curious if you got it all working or have any suggestions!

Cheers!

JR
3  Using Arduino / Networking, Protocols, and Devices / ENC28J60 using HTTP GET to put data through PHP/MySQL database on: May 26, 2011, 02:36:47 am
I've been racking my brains & scouring posts to find a simple (& well commented) example of using ENC28J60 to post data via HTTP GET to PHP/MySQL db, to no avail!

Honestly, I don't care about the PHP/MySQL part, I only care about HOW to make the HTTP Get Request with the EtherShield or EtherCard Library for the ENC28J60!

 I've seen several seemingly overly complex examples with-out much commenting that include: 'Make Arduino a Web Server' or 'Make a Twitter Feed' or other...They are just not clear on what is going on with the Sketch code.  I would think a more simplified example of making the Arduino + ENC28J60 would be more important to get less than skilled programmers the basic tools to make it all work.

I've also seen several posters making the same request I am asking about regarding these little documented libraries (EtherShield library or levera.ging the EtherCard Library from JeeLabs).
 
Does anyway have any suggestions on what to do, or where to look for the explicit example of doing a HTTP GET /save.php?Value=SOMETHING request" ???

Help and Guidance would be very much appreciated!

Cheers,

JR

Pages: [1]