The sketch:
var wifi=require("wifi");
var ESP8266=require("ESP8266");
wifi.connect("xxx", "xxxx",true);
var ipInfo = wifi.getIP();
print("Current IP address is: " + ESP8266.getAddressAsString(ipInfo.ip));
var hostname="api.thingspeak.com";
var temp=23;
var ApiKey="12345678GYGP1";
function send(){
ESP8266.getHostByName(hostname, function(ipAddress){
var http = require("http");
http.get({host:ESP8266.getAddressAsString(ipAddress),port: 80,
path: "/update?key="+ApiKey+"&field1="+temp},
function(response) {
print("get callback!");
response.on("data", function(data) {
print("Data: "+data);
});
response.on("close", function() {
print("The response connection closed");
print(process.memory());
});
});
});
} //functin send
setInterval(function() {
send();
}, 30000);
Error from UART1 - debug port
Host: 144.212.80.11
Dump of socket=264
- isConnected=1, creationType=SOCKET_CREATED_OUTBOUND, acceptedSockets=[], rxBufLen=0, tx length=0, currentTx=0x1073722280, state=SOCKET_STATE_TRANSMITTING, espconn=0x3fffa948, errorCode=0
< net_ESP8266_BOARD_send
>> sendCB
<< sendCB
>> recvCB for socket=264, length=536
Dump of espconn: 0x3fffa948
- type = TCP
- local address = 192.168.0.104 [21150]
- remote address = 144.212.80.11 [80]
- state=READ, link_cnt=99, reverse=0x3ffefd28
<< recvCB
>> recvCB for socket=264, length=82
Dump of espconn: 0x3fffa948
- type = TCP
- local address = 192.168.0.104 [21150]
- remote address = 144.212.80.11 [80]
- state=READ, link_cnt=99, reverse=0x3ffefd28
<< recvCB
>> disconnectCB
Dump of espconn: 0x3fffa948
- type = TCP
- local address = 192.168.0.104 [21150]
- remote address = 144.212.80.11 [80]
- state=CLOSE, link_cnt=99, reverse=0x3ffefd28
Dump of socket=264
- isConnected=1, creationType=SOCKET_CREATED_OUTBOUND, acceptedSockets=[], rxBufLen=618, tx length=0, currentTx=0x0, state=SOCKET_STATE_IDLE, espconn=0x3fffa948, errorCode=0
<< disconnectCB
> net_ESP8266_BOARD_closeSocket, socket=264
Dump of socket=264
- isConnected=0, creationType=SOCKET_CREATED_OUTBOUND, acceptedSockets=[], rxBufLen=0, tx length=0, currentTx=0x0, state=SOCKET_STATE_CLOSING, espconn=0x3fffa948, errorCode=0
> releaseSocket: 264
Dump of socket=264
- isConnected=0, creationType=SOCKET_CREATED_OUTBOUND, acceptedSockets=[], rxBufLen=0, tx length=0, currentTx=0x0, state=SOCKET_STATE_CLOSING, espconn=0x3fffa948, errorCode=0
- freeing espconn: 0x3fffa948
< releaseSocket
< net_ESP8266_BOARD_closeSocket
> jswrap_ESP8266_getHostByName
< jswrap_ESP8266_getHostByName
>> dnsFoundCallback - api.thingspeak.com b50d490
<< dnsFoundCallback
> net_ESP8266_BOARD_createSocket: host: 144.212.80.11, port:80
- espconn: 0x3fffa948
Dump of espconn: 0x3fffa948
- type = TCP
- local address = 192.168.0.104 [26649]
- remote address = 144.212.80.11 [80]
- state=WAIT, link_cnt=99, reverse=0x3ffefd28
< net_ESP8266_BOARD_createSocket, socket=265
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: - Not connected
>> connectCB_outbound
Dump of espconn: 0x3fffa948
- type = TCP
- local address = 192.168.0.104 [26649]
- remote address = 144.212.80.11 [80]
- state=CONNECT, link_cnt=99, reverse=0x3ffefd28
Dump of socket=265
- isConnected=0, creationType=SOCKET_CREATED_OUTBOUND, acceptedSockets=[], rxBufLen=0, tx length=0, currentTx=0x0, state=SOCKET_STATE_CONNECTING, espconn=0x3fffa948, errorCode=0
<< connectCB_outbound
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 64: GET /update?key=123455555YGP1&field1=23 HTTP/1.0
User-Agent:
Dump of socket=265
- isConnected=1, creationType=SOCKET_CREATED_OUTBOUND, acceptedSockets=[], rxBufLen=0, tx length=0, currentTx=0x1073722408, state=SOCKET_STATE_TRANSMITTING, espconn=0x3fffa948, errorCode=0
< net_ESP8266_BOARD_send
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: - Currently transmitting
>> sendCB
<< sendCB
> net_ESP8266_BOARD_send: Request to send data to socket 265 of size 62: Espruino 1v81.722
Connection: close
Host: 144.212.80.11
Dump of socket=265
- isConnected=1, creationType=SOCKET_CREATED_OUTBOUND, acceptedSockets=[], rxBufLen=0, tx length=0, currentTx=0x1073722280, state=SOCKET_STATE_TRANSMITTING, espconn=0x3fffa948, errorCode=0
< net_ESP8266_BOARD_send
>> sendCB
<< sendCB
>> recvCB for socket=265, length=536
Dump of espconn: 0x3fffa948
- type = TCP
- local address = 192.168.0.104 [26649]
- remote address = 144.212.80.11 [80]
- state=READ, link_cnt=99, reverse=0x3ffefd28
<< recvCB
>> recvCB for socket=265, length=82
Dump of espconn: 0x3fffa948
- type = TCP
- local address = 192.168.0.104 [26649]
- remote address = 144.212.80.11 [80]
- state=READ, link_cnt=99, reverse=0x3ffefd28
<< recvCB
>> disconnectCB
Dump of espconn: 0x3fffa948
- type = TCP
- local address = 192.168.0.104 [26649]
- remote address = 144.212.80.11 [80]
- state=CLOSE, link_cnt=99, reverse=0x3ffefd28
Dump of socket=265
- isConnected=1, creationType=SOCKET_CREATED_OUTBOUND, acceptedSockets=[], rxBufLen=618, tx length=0, currentTx=0x0, state=SOCKET_STATE_IDLE, espconn=0x3fffa948, errorCode=0
<< disconnectCB
> net_ESP8266_BOARD_closeSocket, socket=265
Dump of socket=265
- isConnected=0, creationType=SOCKET_CREATED_OUTBOUND, acceptedSockets=[], rxBufLen=0, tx length=0, currentTx=0x0, state=SOCKET_STATE_CLOSING, espconn=0x3fffa948, errorCode=0
> releaseSocket: 265
Dump of socket=265
- isConnected=0, creationType=SOCKET_CREATED_OUTBOUND, acceptedSockets=[], rxBufLen=0, tx length=0, currentTx=0x0, state=SOCKET_STATE_CLOSING, espconn=0x3fffa948, errorCode=0
- freeing espconn: 0x3fffa948
< releaseSocket
< net_ESP8266_BOARD_closeSocket
> jswrap_ESP8266_getHostByName
< jswrap_ESP8266_getHostByName
>> dnsFoundCallback - api.thingspeak.com b50d490
<< dnsFoundCallback
> net_ESP8266_BOARD_createSocket: host: 144.212.80.11, port:80
- espconn: 0x3fffa948
Dump of espconn: 0x3fffa948
- type = TCP
- local address = 192.168.0.104 [39083]
- remote address = 144.212.80.11 [80]
- state=WAIT, link_cnt=99, reverse=0x3ffefd28
< net_ESP8266_BOARD_createSocket, socket=266
Fatal exception 0(IllegalInstructionCause):
epc1=0x4010088d, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 31316, room 16
tail 4
chksum 0xcb
load 0x3ffe8000, len 2124, room 4
tail 8
chksum 0x44
load 0x3ffe8850, len 29772, room 0
tail 12
chksum 0xde
csum 0xde
Restart info:
reason: 2=exception
exccause: 0
epc1: 4010088d
epc2: 0
epc3: 0
excvaddr: 0
depc: 0
Flash map 4MB:512/512, manuf 0xE0 chip 0x4016
Heap: 5792
Variables: 1023 @12ea = 12276bytes
Time sys=301240 rtc=1347213149
mode : softAP(1a:fe:34:fa:35:84)
add if1
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
> initDone
> jshInit
RTC read: 114901 1337384012 0x51b76ebd (0xdeadbeef)
RTC: restore sys=321206 rtc=1347216531
RTC: restored time: 114959 (delta=9832519 cal=5903us)
UStimer init
< jshInit
> jswrap_ESP8266_init
> jswrap_ESP8266WiFi_init
Wifi init, mode=2
< jswrap_ESP8266WiFi_init
< jswrap_ESP8266_init
> jswrap_ESP8266WiFi_init
Wifi init, mode=2
< jswrap_ESP8266WiFi_init
< initDone
Error from Espruino consol
The response connection closed
{ "free": 726, "usage": 297, "total": 1023, "history": 126 }
ASSERT(var && jsvGetRefs(var)>0 && jsvHasRef(var)) FAILED AT src/jsvar.c:561
#1[r2,l2] Object {
#2[r1,l2] Name String [1 blocks] "ÿ" #3[r1,l2] Object {
#6[r1,l2] Name String [1 blocks] "net" #4[r1,l2] String [2 blocks] "\x04\x00\x00\x00\x00ÿÿÿ"
#9[r1,l2] Name String [2 blocks] "timers" #11[r2,l1] Array(2) [
#231[r1,l2] Name Integer 1 #160[r1,l1] Object {
#162[r1,l2] Name String [1 blocks] "time" #236[r1,l1] Integer 29721028
#227[r1,l2] Name String [2 blocks] "interval" #163[r1,l1] Integer 30000000
#229[r1,l2] Name String [2 blocks] "callback" #150[r1,l1] Function {
#147[r1,l2] Name String [1 blocks] "ÿcod" #149[r1,l1] String [2 blocks] "send();"
}
}
]
#12[r1,l2] Name String [2 blocks] "watches" #14[r2,l1] Array(0) [ ]
#15[r1,l2] Name String [2 blocks] "history" #19[r1,l1] Array(12) [
#20[r1,l2] Name Integer 0 #16[r1,l1] String [2 blocks] "echo(0);"
#22[r1,l2] Name Integer 1 #24[r1,l1] String [4 blocks] "var wifi=require(\"wifi\");"
#33[r1,l2] Name Integer 2 #36[r1,l1] String [5 blocks] "var ESP8266=require(\"ESP8266\");"
#47[r1,l2] Name Integer 3 #48[r1,l1] String [6 blocks] "wifi.connect(\"Erni\", \"xxx\",true);"
#46[r1,l2] Name Integer 4 #58[r1,l1] String [4 blocks] "var ipInfo = wifi.getIP();"
#76[r1,l2] Name Integer 5 #77[r1,l1] String [10 blocks] "print(\"Current IP address is: \" + ESP8266.getAddressAsString(ipInfo.ip));"
#74[r1,l2] Name Integer 6 #66[r1,l1] String [5 blocks] "var hostname=\"api.thingspeak.com\";"
#94[r1,l2] Name Integer 7 #91[r1,l1] String [2 blocks] "var temp=23;"
#104[r1,l2] Name Integer 8 #98[r1,l1] String [5 blocks] "var ApiKey=\"12225522222GP1\";"
#144[r1,l2] Name Integer 9 #166[r1,l1] String [61 blocks] "function send(){\n\nESP8266.getHostByName(hostname, function(ipAddress){\n\n var http = require(\"http\");\n http.get({host:ESP8266.getAddressAsString(ipAddress),port: 80,\n path: \"/update?key=\"+ApiKey+\"&field1=\"+temp},\nfunction(response) {\n print(\"get callback!\");\n\n\nresponse.on(\"data\", function(data) {\n print(\"Data: \"+data);\n});\n\nresponse.on(\"close\", function() {\n print(\"The response connection closed\");\nprint(process.memory());\n});\n\n});\n\n});\n\n} //functin send"
#151[r1,l2] Name Integer 10 #152[r1,l1] String [7 blocks] "setInterval(function() {\n send();\n\n}, 30000);"
#161[r1,l2] Name Integer 11 #146[r1,l1] String [2 blocks] "echo(1);"
]
#28[r1,l2] Name String [2 blocks] "modules" #30[r1,l1] Object {
#21[r1,l2] Name String [1 blocks] "wifi" #31[r2,l1] ...
#32[r1,l2] Name String [2 blocks] "ESP8266" #42[r2,l1] ...
#285[r1,l2] Name String [1 blocks] "http" #286[r0,l2] NativeFunction 0x40222b3c (0) { }
}
#331[r1,l2] Name String [2 blocks] "HttpCC" #333[r1,l1] Array(252) [
#328[r1,l2] Name Integer 251 #322[r1,l2] Object {
#323[r1,l2] Name String [2 blocks] "__proto__" #350[r2,l1] ...
#326[r1,l2] Name String [1 blocks] "type"= int 1
#325[r1,l2] Name String [2 blocks] "#onconnect" #289[r1,l1] Function {
#293[r1,l2] Name Param "response" undefined
#244[r1,l2] Name String [1 blocks] "ÿcod" #296[r1,l1] FlatString [18 blocks] "print(\"get callback!\");\n\n\nresponse.on(\"data\", function(data) {\n print(\"Data: \"+data);\n});\n\nresponse.on(\"close\", function() {\n print(\"The response connection closed\");\nprint(process.memory());\n});"
#314[r1,l2] Name String [1 blocks] "ÿsco" #245[r1,l1] Array(2) [
#290[r1,l2] Name Integer 0 #517[r2,l2] Function {
#516[r1,l2] Name String [2 blocks] "return" undefined
}
#291[r1,l2] Name Integer 1 #518[r1,l3] Function {
#511[r1,l2] Name Param "ipAddress" #519[r2,l2] Integer 189846672
#234[r1,l3] Name String [2 blocks] "return" undefined
#237[r1,l2] Name String [1 blocks] "http" #286[r0,l2] ...
}
]
#316[r1,l2] Name String [1 blocks] "ÿlin"= int 19
}
#329[r1,l2] Name String [1 blocks] "res" #319[r1,l1] Object {
#320[r1,l2] Name String [2 blocks] "__proto__" #339[r253,l1] ...
}
#330[r1,l2] Name String [1 blocks] "opt" #240[r1,l1] Object {
#241[r1,l2] Name String [1 blocks] "host" #246[r1,l1] String [3 blocks] "144.212.80.11"
#242[r1,l2] Name String [1 blocks] "port"= int 80
#243[r1,l2] Name String [1 blocks] "path" #283[r1,l1] String [6 blocks] "/update?key=34433333GP1&field1=23"
#317[r1,l2] Name String [2 blocks] "method" #315[r1,l1] String [1 blocks] "GET"
}
#368[r1,l2] Name String [1 blocks] "dSnd" #342[r1,l1] String [17 blocks] "GET /update?key=123456GP1&field1=23 HTTP/1.0\r\nUser-Agent: Espruino 1v81.722\r\nConnection: close\r\nHost: 144.212.80.11\r\n\r\n"
#370[r1,l2] Name String [1 blocks] "sckt"= int 267
}
]
}
#23[r1,l2] Name String [1 blocks] "wifi" #31[r2,l1] NativeFunction 0x40222abc (0) { }
#35[r1,l2] Name String [2 blocks] "ESP8266" #42[r2,l1] NativeFunction 0x40222acc (0) { }
#45[r1,l2] Name String [2 blocks] "EventDetails" undefined
#57[r1,l2] Name String [2 blocks] "ipInfo" #63[r1,l1] Object {
#64[r1,l2] Name String [2 blocks] "__proto__" undefined
#67[r1,l2] Name String [1 blocks] "ip"= int 0
#68[r1,l2] Name String [2 blocks] "netmask"= int 0
#70[r1,l2] Name String [1 blocks] "gw"= int 0
}
#61[r1,l2] Name String [2 blocks] "Restart" undefined
#59[r1,l2] Name String [2 blocks] "hostname" #87[r1,l1] String [3 blocks] "api.thingspeak.com"
#90[r1,l2] Name String [1 blocks] "temp"= int 23
#97[r1,l2] Name String [2 blocks] "ApiKey" #95[r1,l1] String [3 blocks] "123456P1"
#165[r1,l2] Name String [1 blocks] "send" #164[r1,l1] Function {
#143[r1,l2] Name String [1 blocks] "ÿcod" #105[r1,l1] FlatString [38 blocks] "ESP8266.getHostByName(hostname, function(ipAddress){\n\n var http = require(\"http\");\n http.get({host:ESP8266.getAddressAsString(ipAddress),port: 80,\n path: \"/update?key=\"+ApiKey+\"&field1=\"+temp},\nfunction(response) {\n print(\"get callback!\");\n\n\nresponse.on(\"data\", function(data) {\n print(\"Data: \"+data);\n});\n\nresponse.on(\"close\", function() {\n print(\"The response connection closed\");\nprint(process.memory());\n});\n\n});\n\n});"
#145[r1,l2] Name String [1 blocks] "ÿlin"= int 16
}
#334[r1,l2] Name String [2 blocks] "httpCRs" #336[r2,l1] NativeFunction 0x40222aec (1) {
#337[r1,l2] Name String [2 blocks] "prototype" #339[r253,l1] Object {
#340[r1,l2] Name String [2 blocks] "constructor" #336[r2,l2] ...
}
}
#345[r1,l2] Name String [2 blocks] "httpCRq" #347[r2,l1] NativeFunction 0x40222afc (1) {
#348[r1,l2] Name String [2 blocks] "prototype" #350[r2,l1] Object {
#351[r1,l2] Name String [2 blocks] "constructor" #347[r2,l2] ...
}
}
#381[r1,l2] Name String [2 blocks] "process" #353[r1,l1] NativeFunction 0x40222bbc (1) { }
}
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 31316, room 16
tail 4
chksum 0xcb
load 0x3ffe8000, len 2124, room 4
tail 8
chksum 0x44
load 0x3ffe8850, len 29772, room 0
tail 12
chksum 0xde
csum 0xde
don't use rtc mem data
rl?"ÿ
_____ _
| __|___ ___ ___ _ _|_|___ ___
| __|_ -| . | _| | | | | . |
|_____|___| _|_| |___|_|_|_|___|
|_| http://espruino.com
1v81.722 Copyright 2015 G.Williams
>
Disconnected
>