Here is that code, after a while it runs out of memory. I'm doing wrong, or its a bug.
ERROR: Out of Memory!
WARNING: Unable to create string as not enough memory
WARNING: Unable to create string as not enough memory
WARNING: Unable to create string as not enough memory
WARNING: Unable to create string as not enough memory
Execution Interrupted
Execution Interrupted
WARNING: Truncating string as not enough memory
WARNING: Out of memory while appending to array
WARNING: Unable to create string as not enough memory
WARNING: Unable to create string as not enough memory
WARNING: Unable to create string as not enough memory
WARNING: Unable to create string as not enough memory
Execution Interrupted during event processing.
at line 65 col 5
);
^
in function "sendTs" called from line 72 col 24
sendTs(field1, field2);
^
in function called from system
Here is the source code:
var ssid = "ssid";
var pass = "pass";
var ApiKey = 'apikey';
var peri = 30; //period of reading sensor in sec.
var iotHostName="thingspeak.com";
var iotIpAddr="";
var connectToWifi = function() {
console.log('connecting to wifi');
var GPIO2 = new Pin(2);
digitalWrite(GPIO2, 1);
ESP8266WiFi.init();
ESP8266WiFi.connect(ssid, pass, function() {
digitalWrite(GPIO2, 0);
console.log('connected to wifi');
var ipInfo = ESP8266WiFi.getIPInfo();
print("Current IP address is: " +
ESP8266WiFi.getAddressAsString(ipInfo.ip) + ':' +
ESP8266WiFi.getAddressAsString(ipInfo.netmask));
resolveIotAddress(repeat);
});
};
var resolveIotAddress= function(callback)
{
var ESP8266 = require("ESP8266");
ESP8266.getHostByName(iotHostName, function(address) {
iotIpAddr = ESP8266.getAddressAsString(address);
console.log('resolved:' + iotIpAddr);
callback();
});
};
var sendTs = function(press, temp) {
var http = require("http");
http.get({
host: iotIpAddr,
port: 80,
headers: {
'Host': 'tingspeak.com',
},
path: '/update?key=' + ApiKey + '&field1=' + press + '&field2=' + temp
},
function(response) {
print("get callback!");
response.on('data', function(data) {
print(data);
});
response.on('close', function() {
print("The response connection closed");
});
}
);
};
repeat = function() {
var field1 = 1 + Math.floor(Math.random() * 40);
var field2 = 1 + Math.floor(Math.random() * 40);
sendTs(field1, field2);
setTimeout(repeat, peri * 1000);
};
E.on('init', function() {
connectToWifi();
});
thanks
HyGy