/*JSON{ "type" : "staticmethod", "class" : "ESP8266WiFi", "name" : "socketConnect", "generate" : "jswrap_ESP8266WiFi_socketConnect", "params" : [ ["options","JsVar","Some kind of options."], ["callback","JsVar","Some kind of callback."] ], "return" : ["JsVar","A connection object"] }*/ JsVar *jswrap_ESP8266WiFi_socketConnect( JsVar *options, //!< Some kind of options. JsVar *callback //!< Some kind of callback. ) { os_printf("Network state = %d\n", networkState); JsVar *ret = jswrap_net_connect(options, callback, ST_NORMAL); return ret; }
/*JSON{ "type" : "staticmethod", "class" : "http", "name" : "get", "generate" : "jswrap_http_get", "params" : [ ["options","JsVar","An object containing host,port,path,method fields"], ["callback","JsVar","A function(res) that will be called when a connection is made. You can then call `res.on('data', function(data) { ... })` and `res.on('close', function() { ... })` to deal with the response."] ], "return" : ["JsVar","Returns a new httpCRq object"], "return_object" : "httpCRq" } Create an HTTP Request - convenience function for ```http.request()```. `options.method` is set to 'get', and end is called automatically. See [the Internet page](/Internet) for more usage examples. */ JsVar *jswrap_http_get(JsVar *options, JsVar *callback) { JsNetwork net; if (!networkGetFromVarIfOnline(&net)) return 0; if (jsvIsObject(options)) { // if options is a string - it will be parsed, and GET will be set automatically JsVar *method = jsvNewFromString("GET"); jsvUnLock2(jsvAddNamedChild(options, method, "method"), method); } JsVar *skippedCallback = jsvSkipName(callback); if (!jsvIsUndefined(skippedCallback) && !jsvIsFunction(skippedCallback)) { jsError("Expecting Callback Function but got %t", skippedCallback); jsvUnLock(skippedCallback); return 0; } jsvUnLock(skippedCallback); JsVar *cliReq = jswrap_net_connect(options, callback, ST_HTTP); if (cliReq) clientRequestEnd(&net, cliReq); networkFree(&net); return cliReq; }