-
-
you're right, no need for firmata. If I can directly call any function that is even better. I just realized I can connect via CoolTerm on Mac for example and type function calls. This is super sweet, because now I can write a Node.js app that connects over serial easily.
thx for helping me realize :-)
-
I seem to be not successful with the Xively - I used a REST client which gave me the info that it works with HTTP, too, so I gave it a try:
PUT http://api.xively.com/v2/feeds/1848857974
header: X-Api-Key: RMspyWqYIq1m9vEyuF9Q9BLpngLf4Tr1MlEhmDnHTbAjQvG8
body: counter,2in JS it looks like this - but was not able to get a request through:
function putXively() { digitalWrite(LED1,1); var options = { host: 'api.xively.com', port: '80', path:'/v2/feeds/1848857974', method:'put', headers: { "X-ApiKey":"RMspyWqYIq1m9vEyuF9Q9BLpngLf4Tr1MlEhmDnHTbAjQvG8" } }; var req = require("http").request(options, function(res) { res.on('data', function(data) { setTimeout(putXively, 2000); digitalWrite(LED1,0); }); }); req.end("counter," + counter++); }
Yes, I posted my API key. Don't care, this is for testing. Feel free to use exactly the same key. The feed is also public, e.g. can be accessed via https://xively.com/feeds/1848857974
I made a few test calls via RESTclient, so some data is there. But unfortunately did not get a request through via the Espruino+CC3000.
-
It stopped now, this time with an exception:
Success Counter: 319
0000000000000000
ERROR: Timeout in CC3000 driver (4103)
ERROR: Connect failed (err -1)
Looks like CC3000 has died again. Power cycling...
ERROR: Timeout in CC3000 driver (16384)
at line 23 col 13req.end(); ^
in function called from system
Execution Interrupted during event processing - clearing all timers and watches.BTW I am about to figure out xively - I need to make PUT request to a HTTPS url, also need to set a header - so knowing about the headers comes handy. I assume I can use HTTPS - e.g. via "scheme:'https' ?
-
-
-
-
-
HI Gordon, very good info. Thx a lot. I have to correct my info on the CC3000 to some degree BTW. I just had a longer break and left the computer running. Without failing, I had 79+ successful post requests and counting. There seems to be sometimes very large waiting time between the requests, but so far it has not failed with an exception.
-
So the habit / pattern I developed now is this
- change code in the IDE, transfer it over
- in the console, call save() - then it is saved for "standalone" and I don't have to call init.
--> so reset() - I would do this to get a "blank" espruino to play with. But it would not clear the persistent memory, so after a power on/off or reset button press, it would be back as it loads again.
Thx!
- change code in the IDE, transfer it over
-
Hi @Gordon, the "hidden" headers feature is cool, thx!
I am now at home, e.g. a "nice" WiFi environment with only a few devices. I just implemented a tiny counter in the request calls and the maximum requests before it somehow stalled is 22. I have a 2 second delay between the requests right now. The espruino is still working btw, I have a toggle on an LED (interval) and the LED is still flashing. But the 23 request now does not seem to be able to complete.
-
Hi @Gordon, yes 1.51. THX for vbat, i had 3.3 To 3.3 and VIN in cc3000 to vbat. Removed the one cable now, I'll see if that makes it better.
For headers I was thinking outgoing requests, e.g. setting the headers to a request for a remote server call.
Will report later once I am home.
-
I am experiencing issues with the CC3000 in chatty environments, the TI CC3000 seems to be unstable and not able to connect, lose the connection, etc.
I love espruino and the coding style with javascript, but the CC3000 / WiFi might simply be too unstable. In the end I am building prototypes with it that might get presented at conferences and if the wifi is not rock-solid, it is a ticket to fail.
I read the only way to use the internet right now on an Espruino is the CC3000 - but apparently some other options are under way. Will there be a Ethernet option? I know from the experience on Arduino, that Ethernet is typically pretty stable.
@Gordon could you let us know if something is in the works and maybe include a rough timeline? I need some rough outlook as I need to make the decision if espruino can be used for more solid prototypes including HTTP requests in the short/mid/long term.
Thx!
Sven -
Thx Gordon, very cool. BTW would there be a way to extendn the request function to be able to include Request Headers - and potentially access teh response headers?
In general I am super super super happy not to have to deal with the parsing of the raw response, e.g. data in the on('data') even contains the pure body of the response, not the raw headers around it (that's so painful on Arduino).
But I assume sometimes it woudl be nice to access headers. e..g. res.body woudl be the body, by res.headers a map with the headers.
In another post I mentioned that I have issues with the stability. I get erros from the CC3000 but once these happens I have no way to restart the device, other than pressing reset. And especially here in an office environment, the likelihood to get the CC3000 connected and a few requests sent out is very low. The max. number of consecutive post requests I was able to send is two :-) then the CC3000 crashed and all stopped.
Any idea?
-
I saw that you mentioned exception are not supported right now. I am using the Adafruit CC3000 breakout and try to run a http post every 5 seconds to report some button states. I get a
ERROR: Unable to locate host
very often or the cc3000 dies altogether and making the espruino unresponsive and not run any code. Is there any way to recover from such an exception right now?
-
Hi all,
I have trouble to understand when I would call save() load() and reset(). I've declared a few global variables at the top of my espruino code:
var channel, led2State, debug;
These variables are initialized in an onInit() function, that I typically call manually once I have moved the code over to the device. The onInit() function is called once the device starts up - e.g. after a reset button click, right?
Now, I could also make the onIinit() call at the bottom of the code - once I flash the code over, it would execute the onInit() once, - just like after a reset. But a reset - if I understand correctly - will not execute the onInit() twice, as the call to onInit() is done by the system.
Are these assumptions correct?
Is it OK to declare global variables -what happens to these once I do a save()?Thx
Sven -
There is a CC3000 breakout from adafruit. You can very easily connect the wires to the arduino if you solder some pin headers. http://www.adafruit.com/products/1469
Now the only problem that I experience is that the CC3000 does seem to have an unstable firmware, e.g. in chatty office environments, it cannot connect or simply crashes. I am also currently trying to figure out how I could recover from such a crash and restart the espruino including the CC3000 again. If anyone has ideas, please let me know.
-
Hi all,
I am currently exploring the "best" prototyping platform for a little project, I've used the Spark Core already for example and know that the CC3000 seems to have real issues in "chatty" WiFi environments. Nevertheless, I am wondering if there is somethign I could do from an Espruino point of view.
The error I am getting is this:
ERROR: Timeout in CC3000 driver (4103) ERROR: Connect failed at line 22 col 13 req.end(); ^ in function called from system Looks like CC3000 has died again. Power cycling...
My code is doing a HTTP post request, then once data has been received, it will schedule the same request again after 5 seconds. Ideally I would like to get a constant server-client connection, WebSockets or so, but I think if simple HTTP requests are a stability issue, I won't go in this area.
Is there a way to
- make it more stable?
- or could I at least reset the CC3000 somehow, catch the exception it did throw and start again?
Thx!
Sven - make it more stable?
-
This is strange, but using the "raw" request method it does work. I am posting this here so others can have an example of how to use the request method:
var options = { host: 'hybrisiot.appspot.com', port: '80', path:'/shelves/default/status/' + getButtonStatus(), method:'post' }; var req = require("http").request(options, function(res) { res.on('data', function(data) { if (debug) { console.log('> ' + data); } lights(data); setTimeout(postData, 5000); //repeat every 5 sec digitalWrite(LED1,0); }); }); req.end();
Unfortunately I have a new problem - will create a new thread for that.
-
Hi all,
I am very often using Google App Engine to host APIs and I have an API up here
http://hybrisiot.appspot.com/shelves/default
If you call this with a browser or curl, it will respond with a bunch of JSON. It will take longer upon the first request because GAE just fires up the app, but then from the second request it is pretty fast.
Now, with the CC3000 connected, I try to get that JSON response. But I get this in the console:
ERROR: Unable to locate host
ERROR: Timeout in CC3000 driver (4107)
Looks like CC3000 has died again. Power cycling...Below is the espruino js code.
require("http").get("http://hybrisiot.appspot.com/shelves/default", function(res) {
res.on('data', function(data) { console.log(data); }); });
I also tried to use the raw request method - could someone maybe also post an example for a POST with url-encoded body? That woudl be awesome.
-
I've seen the example for the HC-05, which I believe is not a BLE module, right? I got two of these with my kickstarter shipment.
Now I've seen there is a HC-10, too, which seems to be very compatible from the outside:
http://imall.iteadstudio.com/im130614001.htmlIs there a library to use it with espruino for BLE support?
Thx
Sven -
This is a bit strange and most likely user error. But here it is: I created an espruino script with the web ide and create a server on port 80 - this all works when I transfer the script via the web ide.
I then write save(); via the web ide command line to save the program to flash, disconnect from the mac's USB and plug the espruino via the same USB cable into a USB power supply. I've tried this a couple of times now, but the server is no longer available. I also checked my router, the espruino did get assigned the same IP.
Because I had no idea how console.log() works or what it does, I commented out these calls. Would that be OK to leave them in, even though the USB cable is just a power supply?
But again, this does not seem the real issue. Is save() the issue? What do I need to do if I want to save a script in the espruino and boot it up whenever I connect the espruino to power?
Thx
Sven -
Hi all,
first of all let me know that I am super impressed by espruino. I got 4 kickstarter boards including the CC3000 adafruit wifi breakout and creating a server plus responding to requests and serving some JSON response etc. is in total super smooth - compared to other options out there.
I have one question though. Below is the full createServer code, but the code snippet I really don't like right now is this:
if(req.url.substr(0,2) == "/?") digitalWrite(C15, (req.url.indexOf('led=true') != -1));
based on a call to the root resource / I am determining whether to turn an LED on or off. To my knowledge, there is no automatic req.queryString object for example that would give you the queryString. Even better would be to get a pre-parsed map of the querystrings, then I could do:
if (req.params.led == 'true') -> do stuff
The way I found the url property is by JSON.stringifying the req object and that one is pretty large. I might have overlooked something, but I could not find more specific ways to access the path of the call or the queryString and parameters.
Is this planned to be added or somewhere where I just did not find it?
Thx
Svenwlan.connect( "xxx", "xxx", function (s) { if (s=="dhcp") { console.log("My IP is "+wlan.getIP().ip); require("http").createServer(function (req, res) { //turn LED on/off console.log(req.url); if(req.url.substr(0,2) == "/?") digitalWrite(C15, (req.url.indexOf('led=true') != -1)); var obj = {}; obj.success = true; obj.poti = analogRead(A1); res.writeHead(200, {'Content-Type': 'application/json'}); //res.write("{\"success\":true, \"val\":"+analogRead(A1)+"}"); res.write(JSON.stringify(obj)); res.end(); }).listen(80); } });
Strange, i believe this is the normal chrome.
I got a pixel and Work in that, works fine there. But its an annoying issue. It seems just some CSS layout is off. Could it be made Mord stable with some forgiving margins here and there? It looked like the original terminal/code split adds up to exactly 100%, which might stack divs vertically if they don't fit next to each other.