{"action":"created","issue":{"url":"https://api.github.com/repos/espruino/Espruino/issues/863","repository_url":"https://api.github.com/repos/espruino/Espruino","labels_url":"https://api.github.com/repos/espruino/Espruino/issues/863/labels{/name}","comments_url":"https://api.github.com/repos/espruino/Espruino/issues/863/comments","events_url":"https://api.github.com/repos/espruino/Espruino/issues/863/events","html_url":"https://github.com/espruino/Espruino/issues/863","id":158840366,"number":863,"title":"Setting Static IP","user":{"login":"tscrip","id":7517351,"avatar_url":"https://avatars.githubusercontent.com/u/7517351?v=3","gravatar_id":"","url":"https://api.github.com/users/tscrip","html_url":"https://github.com/tscrip","followers_url":"https://api.github.com/users/tscrip/followers","following_url":"https://api.github.com/users/tscrip/following{/other_user}","gists_url":"https://api.github.com/users/tscrip/gists{/gist_id}","starred_url":"https://api.github.com/users/tscrip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tscrip/subscriptions","organizations_url":"https://api.github.com/users/tscrip/orgs","repos_url":"https://api.github.com/users/tscrip/repos","events_url":"https://api.github.com/users/tscrip/events{/privacy}","received_events_url":"https://api.github.com/users/tscrip/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/espruino/Espruino/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/espruino/Espruino/labels/ESP8266","name":"ESP8266","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2016-06-07T05:16:27Z","updated_at":"2016-07-06T19:16:38Z","closed_at":null,"body":"I have been looking through the code, but I currently do not see a way to set a static IP. All of the comments for static IP say this feature if for future development. Is that true?\r\n\r\nI am currently using a ESP8266 if that makes any difference."},"comment":{"url":"https://api.github.com/repos/espruino/Espruino/issues/comments/230875519","html_url":"https://github.com/espruino/Espruino/issues/863#issuecomment-230875519","issue_url":"https://api.github.com/repos/espruino/Espruino/issues/863","id":230875519,"user":{"login":"MaBecker","id":15932646,"avatar_url":"https://avatars.githubusercontent.com/u/15932646?v=3","gravatar_id":"","url":"https://api.github.com/users/MaBecker","html_url":"https://github.com/MaBecker","followers_url":"https://api.github.com/users/MaBecker/followers","following_url":"https://api.github.com/users/MaBecker/following{/other_user}","gists_url":"https://api.github.com/users/MaBecker/gists{/gist_id}","starred_url":"https://api.github.com/users/MaBecker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaBecker/subscriptions","organizations_url":"https://api.github.com/users/MaBecker/orgs","repos_url":"https://api.github.com/users/MaBecker/repos","events_url":"https://api.github.com/users/MaBecker/events{/privacy}","received_events_url":"https://api.github.com/users/MaBecker/received_events","type":"User","site_admin":false},"created_at":"2016-07-06T19:16:38Z","updated_at":"2016-07-06T19:16:38Z","body":"ok - got three functions, first one is doing the work the other two are calling the worker.\r\n\r\nnot sure about the unlocks, call back and parameters .... please assist.\r\n\r\n````\r\nvoid setIP(JsVar *jsSettings, JsVar *jsCallback, int interface) {\r\n\r\n  char ipTmp[16];\r\n  int len = 0;\r\n\r\n  // fist check parameter \r\n  if (!jsvIsObject(jsSettings)) {\r\n    EXPECT_OPT_EXCEPTION(jsSettings);\r\n    return;\r\n  }\r\n\r\n  // get,check and store ip\r\n  JsVar *jsIP = jsvObjectGetChild(jsSettings, \"ip\", 0);\r\n  if (jsIP != NULL && !jsvIsString(jsIP)) {\r\n      EXPECT_OPT_EXCEPTION(jsIP);\r\n      jsvUnLock(jsIP);\r\n      return;\r\n  }\r\n  len = jsvGetString(jsIP, ipTmp, sizeof(ipTmp)-1);\r\n  ipTmp[len]='\\0';\r\n  \r\n  DBG(\">> ip: %s\\n\",ipTmp);\r\n\r\n  info.ip.addr = networkParseIPAddress(ipTmp); \r\n  if ( info.ip.addr  == 0) {\r\n    jsExceptionHere(JSET_ERROR, \"Not a valid IP address.\");\r\n    return;\r\n  }\r\n\r\n// get, check and store gw\r\n  JsVar *jsGW = jsvObjectGetChild(jsSettings, \"gw\", 0);\r\n  if (jsGW != NULL && !jsvIsString(jsGW)) {\r\n      EXPECT_OPT_EXCEPTION(jsGW);\r\n      jsvUnLock(jsGW);\r\n      return;\r\n  }\r\n  len = jsvGetString(jsGW, ipTmp, sizeof(ipTmp)-1);\r\n  ipTmp[len]='\\0';\r\n\r\n  DBG(\">> gw: %s\\n\",ipTmp);\r\n\r\n  info.gw.addr = networkParseIPAddress(ipTmp);\r\n  if (info.gw.addr == 0) {\r\n    jsExceptionHere(JSET_ERROR, \"Not a valid Gateway address.\");\r\n    return;\r\n  }\r\n\r\n  // netmask setting\r\n  JsVar *jsNM = jsvObjectGetChild(jsSettings, \"netmask\", 0);\r\n  if (jsNM != NULL && !jsvIsString(jsNM)) {\r\n      EXPECT_OPT_EXCEPTION(jsNM);\r\n      jsvUnLock(jsNM);\r\n      return;\r\n  }\r\n  len = jsvGetString(jsNM, ipTmp, sizeof(ipTmp)-1);\r\n  ipTmp[len]='\\0';\r\n\r\n  DBG(\">> netmask: %s\\n\",ipTmp);\r\n\r\n  info.netmask.addr = networkParseIPAddress(ipTmp); \r\n  if (info.netmask.addr == 0) {\r\n    jsExceptionHere(JSET_ERROR, \"Not a valid Netmask.\");\r\n    return;\r\n  }\r\n\r\n  jsvUnLock(jsIP);\r\n  jsvUnLock(jsGW);\r\n  jsvUnLock(jsNM);\r\n\r\n  if (interface == STATION_IF ) {\r\n    wifi_station_dhcpc_stop();\r\n    bool ok = wifi_set_ip_info(STATION_IF, &info);\r\n  }\r\n  else {\r\n    wifi_softap_dhcps_stop();\r\n    bool ok = wifi_set_ip_info(SOFTAP_IF, &info);\r\n    wifi_softap_dhcps_start();\r\n  }\r\n\r\n  // Schedule callback\r\n  \r\n  if (jsvIsFunction(jsCallback != NULL)) {\r\n    JsVar *jsSetIP = jsvNewObject();\r\n    jsvObjectSetChildAndUnLock(jsSetIP, \"success\",jsvNewFromBool(ok));\r\n    JsVar *params[1];\r\n    params[0] = jsSetIP;\r\n    jsiQueueEvents(NULL, jsCallback, params, 1); \r\n    jsvUnLock(params[0]);\r\n    jsvUnLock(jsSetIP);\r\n  }\r\n\r\n  return;\r\n};\r\n\r\n//===== Wifi.setIP\r\n/*JSON{\r\n  \"type\"     : \"staticmethod\",\r\n  \"class\"    : \"Wifi\",\r\n  \"name\"     : \"setIP\",\r\n  \"generate\" : \"jswrap_ESP8266_wifi_setIP\",\r\n  \"params\"   : [\r\n    [\"settings\", \"JsVar\", \"Configuration settings\"],\r\n    [\"callback\", \"JsVar\", \"The callback to invoke when ip is set\"]\r\n  ]\r\n}\r\n\r\nThe `settings` object must contain the following properties.\r\n* `ip` IP address as string (e.g. \"192.168.5.100\")\r\n* `gw`  The network gateway as string (e.g. \"192.168.5.1\")\r\n* `netmask` The interface netmask as string (e.g. \"255.255.255.0\")\r\n\r\nReturn \r\n\r\n* success : true | false  \r\n\r\n*/\r\n\r\nvoid jswrap_ESP8266_wifi_setIP(JsVar *jsSettings, JsVar *jsCallback) {\r\n\r\n  DBG(\"> Wifi.setIP\\n\");\r\n\r\n  setIP(jsSettings, jsCallback, STATION_IF);\r\n\r\n  return;\r\n}\r\n\r\n\r\n//===== Wifi.setAPIP\r\n/*JSON{\r\n  \"type\"     : \"staticmethod\",\r\n  \"class\"    : \"Wifi\",\r\n  \"name\"     : \"setAPIP\",\r\n  \"generate\" : \"jswrap_ESP8266_wifi_setAPIP\",\r\n  \"params\"   : [\r\n    [\"settings\", \"JsVar\", \"Configuration settings\"],\r\n    [\"callback\", \"JsVar\", \"The callback to invoke when ip is set\"]\r\n  ]\r\n}\r\n\r\nThe `settings` object must contain the following properties.\r\n* `ip` IP address as string (e.g. \"192.168.5.100\")\r\n* `gw`  The network gateway as string (e.g. \"192.168.5.1\")\r\n* `netmask` The interface netmask as string (e.g. \"255.255.255.0\")\r\n\r\n\r\nReturn \r\n\r\n* success : true | false  \r\n\r\n*/\r\n\r\nvoid jswrap_ESP8266_wifi_setAPIP(JsVar *jsSettings, JsVar *jsCallback) {\r\n\r\n  DBG(\"> Wifi.setAPIP\\n\");\r\n\r\n  setIP(jsSettings, jsCallback, SOFTAP_IF);\r\n\r\n  return;\r\n}\r\n\r\n````"}}
{"actor":{"display_login":"MaBecker"}}