These are chat archives for SmingHub/Sming

4th
May 2017
Alexander V. Ribchansky
@avr39-ripe
May 04 2017 06:56
@piperpilot Hi! Whats wrong with saving wifiStation info?
slaff
@slaff
May 04 2017 07:45
@elamre That should be perfectly possible with the upcoming PR #1112 . I will merge it later today or tomorrow and will explain what needs to be done, if it is not clear.
Elmar
@elamre
May 04 2017 09:56
@slaff Eyyy thats awesome! Wish I had realized that sooner :D Writing the bytes as integers in a string is not the most efficient way of doing things. But it gets it done for now :D
slaff
@slaff
May 04 2017 10:00

The refactored HttpClient and HttpServer are merged now.

You can use the following sample code to send data:

int yourCallbackHandler(HttpConnection& connection, bool success)
{
    debugf("Got response code: %d", connection.getResponseCode());
    debugf("Success: %d", success);
    if(connection.getRequest()->method != HTTP_HEAD) {
        debugf("Got content starting with: %s", connection.getResponseString().substring(0, 50).c_str());
    }

    return 1;
}

HttpClient client;

void ready() 
{
      client.send(
           client.request("http://domain/path/")
           ->setMethod(HTTP_POST)
           ->setBody(<stream-string-or-raw-data>)
           ->onRequestComplete(yourCallbackHandler)
    );
}

For setBody you have the following possibilities // you should use only ONE at a time.

HttpRequest* setBody(const String& body);
HttpRequest* setBody(IDataSourceStream *stream);
HttpRequest* setBody(uint8_t *rawData, size_t length);

You can also process the response body stream, if needed, using:

HttpRequest* setResponseStream(IOutputStream *stream);
Curtis Pope
@piperpilot
May 04 2017 13:29
@avr39-ripe I think I figured it out...I was having a hard time keeping AP active while connecting station to a new AP and saving the info. My app uses a similar setup process as httpServer_configNetwork example and I wanted the AP to stay active to report connection success back to the client browser connected to it. Anyways, I think I have it now and will update the configNetwork example at some point using the new callbacks, etc.
Curtis Pope
@piperpilot
May 04 2017 14:17
@slaff The new HTTPClient and Server look great...applications need some refactoring though
I will get my application switched over today and let you know if I find any issues. Were you able to address the debug information when you refactored? I haven't taken a close look, but the previous debug that was there wasn't really that helpful, there was too much of it and it didn't really make much sense. would also be good to use the multi-level debug to get basic info at higher levels and more detailed info at lower levels
slaff
@slaff
May 04 2017 14:25
@piperpilot For the debug - "helpful" probably depends on the person that is looking at them. I can make sense from most of the debug messages but it requires deeper knowledge about the inner workings. We can refactor the debug messages to use some levels but that will happen in a later refactoring.
There are also places in the Http code that need refactoring, but I will introduce them in a later release, 3.3.3 or something like this, because they will break for sure the existing apps.
Curtis Pope
@piperpilot
May 04 2017 14:27
cool...once I get my app moved over, I will let you know how it works...a few things on compile that I have to fix are:
app/datapush.cpp:15:11: error: 'class HttpClient' has no member named 'setRequestContentType'
datapush.setRequestContentType("application/json");
^
app/datapush.cpp:16:11: error: 'class HttpClient' has no member named 'setRequestHeader'
datapush.setRequestHeader("Accept", "application/json");
^
app/datapush.cpp:27:11: error: 'class HttpClient' has no member named 'setPostBody'
datapush.setPostBody(tempBody);
slaff
@slaff
May 04 2017 14:31
Now the things are separated. There is a HttpRequest that has the methods and there is a HttpClient that can send requests.
One HttpClient can send multiple requests and take care to pipeline them, reuse tcp connection and SSL session resumption.
I have to write short article(s) this week explaining the new changes
Curtis Pope
@piperpilot
May 04 2017 14:34
yup...cool...it all looks good so far...I'm excited to give it a try
slaff
@slaff
May 04 2017 14:35
Look at the PR #1112 and focus on the changes in the samples/* folder.
They should give you hints about the changes.
Curtis Pope
@piperpilot
May 04 2017 14:52
@slaff what is the new equivilent to datapush.setPostBody(tempBody); where datapush is httpClient
slaff
@slaff
May 04 2017 14:53
See the example earlier in the chat
Curtis Pope
@piperpilot
May 04 2017 14:54
I see it...thanks
Curtis Pope
@piperpilot
May 04 2017 18:41
@slaff any idea about this:
/Users/cpope/Development/Sming/Sming//third-party/http-parser/http_parser.c:2159: undefined reference to __assert_func' /Users/cpope/Development/Sming/Sming/compiler/lib//libsming.a(http_parser.o): In functionhttp_errno_name':
/Users/cpope/Development/Sming/Sming//third-party/http-parser/http_parser.c:2163: undefined reference to `__assert_func'
collect2: error: ld returned 1 exit status
make: * [out/build/app_0.out] Error 1
the code its referring to is this:
const char *
http_errno_name(enum http_errno err) {
assert(((size_t) err) < ARRAY_SIZE(http_strerror_tab));
return http_strerror_tab[err].name;
}
Curtis Pope
@piperpilot
May 04 2017 18:49
OK, not sure what the issue was, but I nuked the third-party directory and made it re-download everything and it compiles now.
slaff
@slaff
May 04 2017 18:52
cd $SMING_HOME
git pull
make dist-clean
make
Curtis Pope
@piperpilot
May 04 2017 19:36
@slaff have you tested examples like httpserver_confignetwork? so far, my application is completely unstable and AJAX requests aren't working properly from a browser
Curtis Pope
@piperpilot
May 04 2017 20:25
@slaff I opened up an issue with some more data on the instability I am seeing.
slaff
@slaff
May 04 2017 20:32
@piperpilot There is one issue that I've noticed and this one is related to the JsonStream size. The latest #1114 PR fixes that issue.
Curtis Pope
@piperpilot
May 04 2017 20:37
just saw that...are you going to merge that to develop?
I'm testing it now will let you know if that stabilizes things...any idea about the multiple connections?
slaff
@slaff
May 04 2017 20:51
See my response in #1113. Please, notice that the post data processing in the response has to be re-added. And it will take some days...
Curtis Pope
@piperpilot
May 04 2017 20:53
I'm still not understanding why it isn't multiple TCP connections in #1113... I added another comment. BTW...I don't think this is new behavior. I'm also having an issue with large files from SPIFFs...but haven't narrowed that one down yet...will dig into it as well
slaff
@slaff
May 04 2017 20:58
It can be your browse doing this. Test with simple tools like curl.
Curtis Pope
@piperpilot
May 04 2017 21:00
yeah, interesting...seems to be a chrome thing...curl and safari its only 1 connection
Curtis Pope
@piperpilot
May 04 2017 21:06
One other thing I seem to be getting is: GET http://192.168.4.1/ net::ERR_CONTENT_LENGTH_MISMATCH
I'll open a new issue on that with some logging