-
If I'm not passing the array as a flat data area in the ram, the source code says, that I'm getting an array of JSVar pointers instead. So would it be correct to have an **int params parameter then, since it's actually an array of pointers. How do I retrieve the value of this variable then? Is there some param[0]->get_value()? I did not find anything in the source code.
But I actually would prefer the flat array option, since this makes working with the values far easier. As said in a comment above: I'm really not that into C at all. I'm just tinkering around with it. Thanks for any of your help. -
Thank you for your reply. Your advice at least solves part of the problem. Now the first variable in the array params[0] is the expected value. But unfortunately not the others (params[1..n]).
I tried padding the Uint32Array to 32bytes and 64bytes without any further luck. Do you have any other Idea? Does it have something to do with signed or unsigned bytes? -
I also tried to change my C-function signature to
int find_sequence(unsigned char* buffer, unsigned char* sequence, int sequence_length, int* params) {}
And pass in an Int32Array. This does not work either. What I noticed is, that whenever I'm returning any of the values from params, I get a static value, which stays the same - so something more like a fixed memory address. But I read that accessing a value by ptr[X] automatically dereferences it and lets me access the value as *(ptr + 0) would do.
-
Hi Gordon, I just came accross this question here and I've the same problem as user113695. I followed your advice, but I just get "garbage" data delivered in my C-function.
I'm not the C guy, so I definitly doing something wrong here
C-Function:// int find_sequence(int, int, int, int) int find_sequence(unsigned char* buffer, unsigned char* sequence, unsigned int sequence_length, unsigned int* params) {... return params[0]; }
And in the code I'm calling it with
const result = findNative.find_sequence( E.getAddressOf(this.buffer, true), E.getAddressOf(sequence, true), sequence.length, E.getAddressOf(new Uint32Array([ this.idx, this.next, offset, stepping ]), true) );
The first three parameters are working beautifully. No matter if I'm accessing params[0], params[1], params[2] or params[3], they all seem to have random values stored within.
Could you help out Gordon?
Thank you very much in advance. -
-
Ok, I found the mistake. "continue" is not supported. As I fixed that it worked after turning off any minification of the code. If I minify, it does somehow not work anymore but does not give me any hint why. I was finally able to shave off another 150ms from my computation, which is very good :) Thank you very much Gordon.
-
Thank you very much. After a bit of experimenting, I'm currently trying to find out, why the following function hangs indefinitly. It's a function which scans a portion (from this.idx to this.next) of an array for a given sequence, starting at an offset using a given stepping width.
find(sequence, offset, stepping) { "jit"; if (stepping === undefined) { stepping = 1; } if (offset === undefined) { offset = 0; } for (let i = this.idx + offset; i < this.next - sequence.length; i+=stepping) { if (this.buffer[i] !== sequence[0]) { continue; } let idx = i; for (let j = 1; j < sequence.length; j++) { if (this.buffer[i + j] !== sequence[j]) { idx = -1; // JIT lacks break statement j = sequence.length - 1; } } if (idx !== -1) { return idx; } } return -1; }
When I run it without jit it works as expected. If the function is jitted, the application hangs without any error. Thank you for your reply
-
-
-
This does work, but I really would like to use class notation.
var A = function() {}; var B = function() { A.call(this); }; B.prototype = Object.create(A.prototype); B.prototype.constructor = B; var C = function() { B.call(this); }; C.prototype = Object.create(B.prototype); C.prototype.constructor = C; function onInit() { const c = new C(); }
-
class A { constructor() {} } class B extends A { constructor() { super(); } } class C extends B { constructor() { super(); } } function onInit() { const c = new C(); }
Hi, I have a problem, which could be boiled down to the code snippet given above.
If I run it on my Espruino WiFi (2v16), I get a recursion error, since if class B tries to call the constructor of A, it calls its own constructor.
Does anyone has a workaround for this problem? I already tried passing different argument lists into the constructors to make them distinguishable (in C++ mapping terms at least). Without any luck. I can easily instantiate B or A, but not C.
I would really appreaciate your help. Thank you very much. -
Hi all,
I have a question, where I really got stuck: Since my code grows in size, I'm encountering more and more often that the serial output is stuck telling me calculating size... and does not move on any bit.
The whole console output is as follows:save() =undefined Compacting Flash... Calculating Size...
Does anyone know why it gets stuck there? My code is compacted the size of roughly 40kb. I'm compacting using the online closure compiler.
I have 4 precompiled functions using the Espruino compilation service.
Thanks for your reply. I'm currently using the latest travis build (lv96.35) -
-
Hi there,
I got the following problem:
I want to the CMPS10 acceleromometer sensor and the Espruino Wifi at the same time. I'm now struggeling getting them to run smoothly. As soon as I call espruino_wifi.connect (whereas espruino_wifi references the EspruinoWiFi module) the data from I2C Bus freezes somehow and the sensor does not deliver any data anymore. I'm powering the sensor through the 3.3V output on the Espruino Board.
Separatly they work beautifully.
Thank you in advance for any idea :)The three numbers are readings from my sensor. As soon as the WiFi module kicks in, the values freeze.
>Loading 48629 bytes from flash... 0.00097657740 0.20996414129 0.88868543526 0.01464866102 0.18359655146 0.93165484092 0.04199282825 0.17578393224 0.95606927595 > 0.00585946440 0.19433890287 0.92677195391 0.01367208361 0.17773708705 0.95411612115 Connecting to access point using EspruinoWiFi module 0.03027389944 0.14941634241 0.95020981155 -0.01068131532 0.18359655146 0.93751430533 -0.01556420233 0.16992446784 0.93556115053 -0.01556420233 0.16992446784 0.93556115053 -0.01556420233 0.16992446784 0.93556115053 -0.01556420233 0.16992446784 0.93556115053 -0.01556420233 0.16992446784 0.93556115053 -0.01556420233 0.16992446784 0.93556115053 Successfully connected to Access Point -0.01556420233 0.16992446784 0.93556115053 -0.01556420233 0.16992446784 0.93556115053 -0.01556420233 0.16992446784 0.93556115053 -0.01556420233 0.16992446784 0.93556115053
-
Hi Gordon, I got it working.
What did I do:- Use the ESP8266WiFi_0v25 library and connect to the onboard wifi controller. (Do manual Serial configuration as stated above)
- Moved from latest travis build to normal v95 build.
- Reinstalled the WebIDE since it was somehow responsible for not being able to load any module anymore (checked offline mode - it was off)
- And now: it works like a charm.
My problem with this HTTP stuff was related to the external ESP8266 in my opinion.
Thank you very much for your immediate help.
- Use the ESP8266WiFi_0v25 library and connect to the onboard wifi controller. (Do manual Serial configuration as stated above)
-
-
Hi Gordon,
I used the ESP8266WiFi_0v25 module and it works once now :) So when I power down my Espruino and power it up again, one request gets executed flawlessly. Any succeeding request gets stuck as before. But it's more than before. I will try whether I powered the integrated board down accidentially. -
Hi Gordon,
thank you for your reply. There is no serial connection possible anymore (Over Serial2 --> Serial2.setup(9600, { rx: A3, tx : A2 });). Any AT+* command could not be sent to the board since there seem to be no connection.
I did not try to reflash the ESP8266 onboard module.(Is there a manual for that?)
Is there any documentation of how to connect the flow control to the external WiFi module?The full code is as follows:
Serial1.setup(115200, { rx: B7, tx : B6 }); var esp8266 = require('ESP8266WiFi'); console.log("Connecting to ESP8266"); var wifi = esp8266.connect(Serial1, function() { console.log("Connecting to WiFi"); wifi.reset(() => { /*Does not close all sockets, I assume --> CIPServer creation fails after some restarts of the Espruino*/ console.log('Reset WiFi'); console.log('Creating access point'); wifi.createAP('BLA', '12345678', 1, 0, (err) => { if (err) { console.log('An error occured:'); console.log(err); return; } console.log('Access Point created'); require('http').createServer((req, res) => { req.on('end', function() { console.log('request stream end (http.incomingMessage stream)'); }); res.on('end', function() { console.log('response finish (http.serverResponse)'); }); req.on('close', function() { console.log('request close (http.incomingMessage)'); }); res.on('close', function() { console.log('response close (http.ServerResponse)'); }); console.log('Request Headers:'); console.log(req.headers); console.log('Request Method:'); console.log(req.method); var a = url.parse(req.url, true); res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(JSON.stringify(a)); }).listen(80); console.log('Http server created'); }); }); });
-
Hi there,
I have problem sending a http response back to the client.
My setup is as follows: Since the WiFi module on my EspruinoWiFi is broken, I wired an external ESP8266 module to the board. I create an access point and after that an http server by calling http.createServer((req, res) => {...}).listen(80)Now my problem:
When I connect to the AccessPoint and send a http GET request to my Esprunino, it gets the request data.
But when I call res.writeHead(200, { 'Content-Type': 'text/plain'}); res.write('Foo'); res.end(); in succession the client never gets any response and the connection seems to stay open forever. Am I doing s.th. wrong?For debug purposes I registered Event listeners on req.on('end', () => {...}), req.on('close', () => {...}), res.on('end', () => {...}) and res.on('close', () => {...}).
The events are getting called in the following order:
request.end
response.end
request.close
response.closeSeems to me, that nothing is going wrong. I'm using the latest firmware (v95). Does anyone has a solution for this? Thank you in advance
Now it gets really strange: This works, but why?
Accessing data at index 0, 8, 12 and 13. Any other "configuration" using different 0-spacings does not work. I'm completly lost.