Closed jakvike closed 11 years ago
I've done something like this with a library I wrapped around WiFlyHQ. It took me some trial and error to figure out what headers I needed to be able to make a post. In particular, look at https://github.com/bsalinas/WebTrestle/blob/master/Arduino/WiFlyHQTrestle/WiFlyHQTrestle.cpp
boolean WiFlyHQTrestle::makePost(char* request, char* data){
if(_wifly-> isConnected()){
_wifly->close();
}
if (_wifly->open(_site, _port)) {
_wifly->print("POST ");
_wifly->print(request);
_wifly->println(" HTTP/1.1");
_wifly->println("Content-Type: application/x-www-form-urlencoded");
_wifly->println("Connection: close");
_wifly->print("Host: ");
_wifly->println(_site);
_wifly->print("Content-Length: ");
_wifly->println(strlen(data));
_wifly->println();
_wifly->print(data);
return waitForResponse();
}
return false;
Here, request
looks something like \add_measurement
and data
looks like "name=789&description=123456&identifier=ABC"
Not sure if this is what you are looking for or not.
Great start to a restful api. Do you mind if email you personally? If so email me @ jakvike@gmail.com please. On Nov 25, 2012 1:49 PM, "Ben Salinas" notifications@github.com wrote:
I've done something like this with a library I wrapped around WiFlyHQ. It took me some trial and error to figure out what headers I needed to be able to make a post. In particular, look at https://github.com/bsalinas/WebTrestle/blob/master/Arduino/WiFlyHQTrestle/WiFlyHQTrestle.cpp
boolean WiFlyHQTrestle::makePost(char* request, char* data){ if(_wifly-> isConnected()){ _wifly->close(); } if (_wifly->open(_site, _port)) { _wifly->print("POST "); _wifly->print(request); _wifly->println(" HTTP/1.1"); _wifly->println("Content-Type: application/x-www-form-urlencoded"); _wifly->println("Connection: close"); _wifly->print("Host: "); _wifly->println(_site); _wifly->print("Content-Length: "); _wifly->println(strlen(data)); _wifly->println(); _wifly->print(data); return waitForResponse(); } return false;
Here, request looks something like \add_measurement and data looks like "name=789&description=123456&identifier=ABC"
Not sure if this is what you are looking for or not.
— Reply to this email directly or view it on GitHubhttps://github.com/harlequin-tech/WiFlyHQ/issues/16#issuecomment-10697439.
I am starting on a object oriented approach to your implementation.
I am not saying this is the best approach just a start and a thought.
class Common {protected:
char * Name;
char * Description;
virtual int Add(T) = 0;
virtual int Remove(T) = 0;}
class Station: public Common{public:
bool Override;
// Station Constructor (name, description, override).
Station(char, char, bool);
int Add(Station& station);
int Remove(Station& station);}
class Sensor: public Common{public:
char * Identifier;
char * Units;
// Sensor Contructor (identifier, name, description, units).
Sensor(char, char, char, char);
int Add(Sensor& sensor);
int Remove(Sensor& sensor);}
class State: public Common{public:
char * Identifier;
// State Constructor (identifier, name, description).
State(char, char, char_);
int Add(State& state);
int Remove(State& state);}
class Bridge: public Common{public:
char * Site;
int Port;
// product wifly or Ethernet?
// Bridge Constructor (stationidentifier, site, port, product).
Bridge(char, char, int);
int Add(Bridge& bridge);
int Remove(Bridge& bridge);}
class Action: public Common{public:
char * Identifier;
ActionFunctionPtr Func;
// Action Constructor (identifier, name, description, Action function).
Action(char, char, char, ActionFunctionPtr);
int Add(Action& action);
int Remove(Action& action);}
template
Thank you,
Jake Kapp jakvike@gmail.com
On Sun, Nov 25, 2012 at 3:11 PM, Jake jakvike@gmail.com wrote:
Great start to a restful api. Do you mind if email you personally? If so email me @ jakvike@gmail.com please. On Nov 25, 2012 1:49 PM, "Ben Salinas" notifications@github.com wrote:
I've done something like this with a library I wrapped around WiFlyHQ. It took me some trial and error to figure out what headers I needed to be able to make a post. In particular, look at https://github.com/bsalinas/WebTrestle/blob/master/Arduino/WiFlyHQTrestle/WiFlyHQTrestle.cpp
boolean WiFlyHQTrestle::makePost(char* request, char* data){ if(_wifly-> isConnected()){ _wifly->close(); } if (_wifly->open(_site, _port)) { _wifly->print("POST "); _wifly->print(request); _wifly->println(" HTTP/1.1"); _wifly->println("Content-Type: application/x-www-form-urlencoded"); _wifly->println("Connection: close"); _wifly->print("Host: "); _wifly->println(_site); _wifly->print("Content-Length: "); _wifly->println(strlen(data)); _wifly->println(); _wifly->print(data); return waitForResponse(); } return false;
Here, request looks something like \add_measurement and data looks like "name=789&description=123456&identifier=ABC"
Not sure if this is what you are looking for or not.
— Reply to this email directly or view it on GitHubhttps://github.com/harlequin-tech/WiFlyHQ/issues/16#issuecomment-10697439.
I am attempting to build a RESTful POST into my wifly. but having trouble getting anything past POST / HTTP/1.1.
Anyone have a clue on getting the Request body?