Arduino - Passing long String to a Library - string

I am trying to write my first big Arduino Library, in this case to control the ESP8266.
I would like to pass as parameter the WEBSITE address to a method that will do the GET request so I need to send two long Strings:
(1) Fix part of the website url
(2) json with the data to add to
the request
1) The fix part is this:
#define WEBPAGE "/mywebsiteURLfolder/post.php?json={"
So I call my library method:
myESPinstanceSOFT.Send_OnlineService(1, HOST, WEBSITE, 9);
And my library should receive it and use to create a final String that will be used to send it via Serial to the ESP8266:
bool ESP8266Class::Send_OnlineService(byte type, String HOST, String WEBPAGE, int Node_ID){
String request = "GET ";
request += WEBPAGE;
request += "Node_ID:";
etc etc
Given that WEBSITE is a fix string. How can I save it in flash and just point to it when constructing the request string?
Thank you very much

Related

How do you get the response as a string using the http_url_get method in rpg

Good day,
I am trying to consume a get method on a server hosted locally.
rc = http_url_get('http://sss:13013/cgi-bi/sendms?'
+ 'username=cous&pas'
+ 'to=' + vCell + '&text=' + %TRIM(vSMSText):
'/tmp/httptest.html');
I am using a library called HTTPAPI its from https://www.scottklement.com/httpapi/
I am trying to figure out how to get the response of the call as a string.
The Variable rc contains a integer response code but no response, I am assuming it gets downloaded to the /tmp/httptest.html parameter specified. But I want it as a string as I want to process the response as a string. I do not know if there is a extra parameter that I can use to store the result of the call.
I have tried the http_string method but I get an error that the method is undefined, I think the my client is using an old version of the HTTPAPI lib.
Is it possible to use the http_url_get function to return the response as a string?.
if you want to get a string response, use Klement's HTTP_req(). It is flexible enough to get a file or a string (and use a file or a string to send a request). You can play with *omit to select the way you can make a GET (on other actions).

Get wrong parameter from get method in nodejs

I'm trying to send get method request and want to pass value in URL.
Like my api look like
app.get('/api/getlocation/:customerName', customer.getlocation);
For call this I wrote in postman
localhost:8080/api/getlocation/:customerName=kumbhani
For test
var customerName = req.params.customerName;
console.log('name', customerName); // =kumbhani
It returns name with = sign - I want only kumbhani
The colon character in the path in Express has a special meaning: whatever you put in the URL after getLocation/ will be put in req.params.customerName.
This means in Postman, you should actually call this URL:
localhost:8080/api/getlocation/kumbhani
→ See related question.

Arduino read get values after ? in url with ethernet shield

Sorry if it has been asked before but I cannot find anything on the internet. I just want to host a page in arduino ethernet shield and when I visit it from a browser with Get parameters (e.g http://xxx.xxx.xx.xx/led.html?red=255,green=0,blue=255) to change to change the led's color. I cannot find how to send data from browser to arduino.
The answer involves the use of The Ethernet Library (Ethernet.h) - which provides an interface to Client and Server, a degree of conceptualizing low-level I/O and buffering the input, and context.
In the following code snippet ( of the sample code at http://arduino.cc/en/Tutorial/WebServer )
...
char c = client.read();
Serial.write(c);
...
the line char c = client.read() is taking a byte from the request stream and assigning it to a char type, it is then serialing that charbyte to a string where it perform conditional logic on it.
The conditional logic of that sample only cares about reading whether a return character \n on a blank line, but the bytes that are being read (on each iteration) byte to byte, actually compose the RAW Request.
At minimal, a RAW HTTP GET Request looks like this:
GET /?first=John&Last=Doe HTTP/1.1
Host: localhost
So, for you to read the query string, you'll need to buffer the bytes being read from the stream.
Then, you'll likely serialize the whole buffer into a string, and perform string operations on them, as well as your conditional logic....

Monotouch/iPhone - Call to HttpWebRequest.GetRequestStream() connects to server when HTTP Method is DELETE

My Scenario:
I am using Monotouch for iOS to create an iPhone app. I am calling ASP.NEt MVC 4 Web API based http services to login/log off. For Login, i use the POST webmethod and all's well. For Logoff, i am calling the Delete web method. I want to pass JSON data (serialized complex data) to the Delete call. If i pass simple data like a single string parameter as part of the URL itself, then all's well i.e. Delete does work! In order to pass the complex Json Data, here's my call (i have adjusted code to make it simple by showing just one parameter - UserName being sent via JSON):
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://localhost/module/api/session/");
req.ContentType = "application/json";
req.CookieContainer = jar;
req.Method = "Delete";
using (var streamWrite = new StreamWriter(req.GetRequestStream()))
{
string jSON = "{\"UserName\":\"" + "someone" + "\"}";
streamWrite.Write(jSON);
streamWrite.Close();
}
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
on the server, the Delete method looks has this definition:
public void Delete(Credentials user)
where Credentials is a complex type.
Now, here's the issue!
The above code, gets into the Delete method on the server as soon as it hits:
req.GetRequestStream()
And hence the parameter sent to the Delete method ends up being null
And here's the weird part:
If i use the exact same code using a test VS 2010 windows application, even the above code works...i.e it does not call Delete until req.GetResponse() is called! And in this scenario, the parameter to the Delete method is a valid object!
QUESTION
Any ideas or Is this a bug with Monotouch, if so, any workaround?
NOTE:
if i change the Delete definition to public void Delete(string userName)
and instead of json, if i pass the parameter as part of the url itself, all's well. But like i said this is just a simplified example to illustrate my issue. Any help is appreciated!!!
This seems to be ill-defined. See this question for more details: Is an entity body allowed for an HTTP DELETE request?
In general MonoTouch (based on Mono) will try to be feature/bug compatible with the Microsoft .NET framework to ease code portability between platforms.
IOW if MS.NET ignores the body of a DELETE method then so will MonoTouch. If the behaviour differs then a bug report should be filled at http://bugzilla.xamarin.com

What can be better way to send WBXML data to web server?

Please could you help me in sending a data from Mobile appication to Web Server in WBXML format ? I have got a bit to convert xml to wbxml but not getting how to send that to web server in efficient way ?
I'm not sure I fully understand your question but here goes...
You need to use a POST HTTP request, and write the WBXML data to the connection objects output stream. Here is a brief example, obviously you'll need more code for it to actually work:
byte[] wbxml = getMyWbxmlData();
HttpConnection conn = (HttpConnection)Connector.open("http://myserver.com/mywbxmlhandler");
conn.setRequestMethod(HttpConnection.POST);
OutputStream output = conn.openOutputStream();
output.write(wbxml);
InputStream input = conn.openInputStream(); // This will flush the outputstream
// Do response processing
That is all assuming your WBXML already includes the preamble, such as version number, public code page identifier etc.

Resources