Chat freely about the open source Javascript projects for ESP8266

User avatar
By xtal
#32113 I was just wanting a GENERAL EXAMPLE :mrgreen:

I managed to write a piece of code using table stuff, it took over 4k
went back to if/elseif etc , this took over 2k
now back to the not enough memory wall, oh well :?
User avatar
By hygy
#32830 Hi, but this all of original espruino, I think some of the examples now working as it is with esp8266 (nodemcu) couse the different hardware. Eg I tried the button example, and cannot use it. (mybe my fault).

HyGy

kolban wrote:
We find a link at the top called "Documentation" and it seems to have a large "Tutorials and Examples" set of pages.

Could this be what you are looking for?

A program written in JavaScript for Espruino should work just the same on all boards that Espruino works upon.
User avatar
By kolban
#32846 The good news is that if you run into problems, we are here to help. There may very well be things on the Espruino port to the ESP8266 that are not working properly yet and ... if there are ... we'll do our hardest to fix them. Feel free to post in this forum or drop by live in the Gitter stream at:

https://gitter.im/espruino/Espruino
User avatar
By jankop
#32855 Hi Neil,
I have problem with stability of Espruino. My programs after a period of operation always collapse . For example, if esp8266 fail to connect to wifi, then in a short time collapse.
wifi.connect() do not change AP mode to station mode!
The following program after some time running crashes as well.

Code: Select allvar ssid = "SSID";
var pass = "Password";
var ApiKey = 'APIKey';
var altitude = 188; // current altitude in m
var mode = 2; //resolution of sensor conversion (0-3)
var afdt = 2; //present numbers after dot
var press = 0; //pressure
var temp = 0; //temperature
var peri = 15; //period of reading sensor in sec.
var cl = 0; // SCL to GPIO0
var da = 2; // SDA to GPIO2
//var bmp = require("BMP085").connect(I2C1, mode);
var http = require("http");
var wifi=require("wifi");
var ESP8266 = require("ESP8266");

print('Connecting to wifi');
         wifi.connect(ssid, pass,null, function(err) {
    print("Wifi error  ", err);
    var ipInfo = wifi.getIP();
    print("Current IP address is: " +
        ESP8266.getAddressAsString(ipInfo.ip) + ':' +
        ESP8266.getAddressAsString(ipInfo.netmask));
});


function aftDot(number, ad) //Formatting numbers.
{
 return Math.round(number*Math.pow(10,ad))/Math.pow(10,ad);
}

function readBMP() //read BMP85 or BMP180 sensor
{       var bmp = require("BMP085").connect(I2C1, mode);
        bmp.getPressure(function(d) {
        press = aftDot(bmp.getSeaLevel(d.pressure, altitude) / 100, afdt);
        temp = aftDot(d.temperature, afdt);
        console.log("\nPressure at sea level: " + press + " hPa");
        console.log("Temperature: " + temp + " C");
    });
    return;
}

function sendTs(press, temp) {
    http.get({
            host: "184.106.153.149",
            port: 80,
            path: '/update?key=' + ApiKey + '&field3=' + press + '&field4=' + temp
        },
        function(response) {
              response.on('data', function(data) {
              print("Callback :",data);
            });
            response.on('close', function() {
                print("Connection closed");
            });
        }
    );
}
I2C1.setup({
    scl: cl,
    sda: da
});

function repeat() {
    readBMP(), sendTs(press, temp), setTimeout(repeat, peri * 1000);
}
  repeat();

Output:

Code: Select all>
Pressure at sea level: 1031.26 hPa
Temperature: 21.66 C
Callback : 1262
Connection closed
>
Pressure at sea level: 1031.36 hPa
Temperature: 21.67 C
Callback : 1263
Connection closed
WARNING: Prototype is not an Object, so setting it to {}
ASSERT(!jsvIsStringExt(v)) FAILED AT src/jsvar.c:534
  #1[r3,l2] Object {
    #2[r1,l2] Name String [1 blocks] "ÿ"      #3[r1,l2] Object {
        #6[r1,l2] Name String [1 blocks] "net"          #4[r1,l3] String [2 blocks] "\x04\x00\x00\x00\x00ÿÿÿ"
        #9[r1,l2] Name String [2 blocks] "timers"          #11[r2,l2] Array(514) [
            #193[r1,l3] Name Integer 512              #935[r1,l2] Object {
                #79[r1,l2] Name String [1 blocks] "time"= int 127
                #78[r1,l2] Name String [2 blocks] "callback"                  #332[r2,l3] ...
 
              }
            #390[r1,l2] Name Integer 513              #396[r1,l1] Object {
                #393[r1,l2] Name String [1 blocks] "time"                  #394[r1,l1] Integer 45503
                #392[r1,l2] Name String [2 blocks] "callback"                  #421[r1,l1] Function {
                    #413[r1,l2] Name String [1 blocks] "ÿcod"                      #420[r1,l1] String [3 blocks] "{b(a.read16(246))}"
                    #399[r1,l2] Name String [1 blocks] "ÿsco"                      #415[r1,l1] Array(2) [
                        #401[r1,l2] Name Integer 0                          #564[r17,l1] ...
 
                        #400[r1,l2] Name Integer 1                          #522[r1,l1] Function {
                            #426[r1,l2] Name Param "b"                               #521[r1,l1] Function {
                                #520[r1,l2] Name Param "c"                                   undefined
                                #439[r1,l2] Name String [1 blocks] "ÿcod"                                  #519[r1,l1] String [46 blocks] "{a.readRawPressure(function(f){var g=\nMath.round((c-a.ac6)*a.ac5/32768),g=g+Math.round(2048*a.mc/(g+a.md)),e=g-4E3;f=Math.round((f-((4*a.ac1+(a.b2*(e*e>>12)>>11)+(a.ac2*e>>11)<<a.oss)+2>>2))/(a.ac4*(((a.ac3*e>>13)+(a.b1*(e*e>>12)>>16)+2>>2)+32768)>>15)*(5E4>>a.oss))<<1;b({pressure:f+(((f>>8)*(f>>8)*3038>>16)+(-7357*f>>16)+3791>>4),temperature:(g+8)/160})})}"
                                #427[r1,l2] Name String [1 blocks] "ÿsco"                                  #432[r1,l1] Array(2) [
                                    #429[r1,l2] Name Integer 0                                      #564[r17,l1] ...

etc....