-
-
Hi all
As part of my car tracker project I'm using a 6000mAh lipo via the jst connector. I have a rough projected lifetime before requiring a recharge but I think it would be more useful to send the battery voltage as part of my GPS coordinate SMS.
Is there any way I can read the voltage of the battery via the jst?
-
-
@Gordon the gsm2 click supports 3.3v io but still requires a 5v line in. This has been brought up a number of times on their forum as their marketing seemed to suggest it would only need the 3.3v in.
@DrAzzy I'm fitting the whole project into a black vox which is 7*4*3 inches. There is probably about 4*2*2 inches left after adding all my other components in. Weight is no issue within reason.
-
Hi All,
I'm looking to move away from my power bank (via usb) and get a battery that utilises the battery socket on my Espruino. I'd like to keep the power bank for my other prototyping so it's time to hunt down a different power source.
I'd like some help on picking out a battery and a suitable charging unit. My project currently requires me to supply 5V with peaks of 2A to power a GSM board as well as GPS & the Espruino.
My power bank is a 10,000 mAh and supplied 5V/2A I don't mind dropping down to around 6000mAh but anything above and closer to the 10k would be excellent.
Any recommendations? I noticed li-po are mostly at 3.7v so I would need a booster to get the 5v but no ideas on what combinations will work best. I'm currently having a read through the adafruit website.
-
-
Hi all,
I'm using the AT module to send messages for interfacing to my GSM.
I've noticed I'm seeing a few errors pop out every so often when viewing the console:
Shutting down GSM Module ] "undefined1\r\n\r\nOK" <--- "1\r\n\r\nOK" ] "OK\r\n" <--- "\r\n" Uncaught Error: Field or method "0" does not already exist, and can't create it on undefined at line 1 col 139 ...)==f&&(b=c[f](b));"\n"==b[0]&&(b=b.substr(1));for(a=b.indexO... ^ in function called from system ] "\r" <--- "\r" ] "\nNO" <--- "\nNO" ] "NORMA" <--- "RMA" ] "NORMAL P" <--- "L P" ] "NORMAL POWE" <--- "OWE" ] "NORMAL POWER D" <--- "R D" ] "NORMAL POWER DOWN" <--- "OWN" ] "NORMAL POWER DOWN \r\n" <--- " \r\n" ] "\r\n" <--- "\r\n" Module Off
Obviously without viewing all of my code this is hard to track down but if someone could point my to where the AT command library is hitting this error I dont mind looking through my own code to pinpoint the issue. I'm assuming its something to do with registering listeners?
-
I am using the GSM2 Click with the espruino for GSM. There is an AT library (https://github.com/espruino/EspruinoDocs/blob/master/modules/AT.js) that has been utilised within the wifi modules and some of the others. I am using this library to send commands to my GSM module.
Example code:
var at = require("AT").connect(Serial4); function SendSMS(phone_num,message,callback){ at.cmd('AT+CMGS=\"'+phone_num+'\"\r',1000,function(e){ console.log('Phone number set:' + phone_num); at.cmd(message,1000,function(f){ console.log('Message text set:' +message); at.cmd("\x1A\r",1000,function(g){ console.log('Sending'); return callback('Message sent'); }); }); }); }
-
Im going to be building in a basic check to see if the module is on.
You should be able to send the "AT" command and receive an "OK" back. This can then probably be expanded out for most other commands. When a command is issued we can check the response against the expected response and start to handle errors better then.
-
@user7143 looking good! Seems like we are getting somewhere now
-
-
So I assume best way is to check the differences between two traces() at any time?
If so this is what I found:
http://www.diffchecker.com/nt8yotd5"line" mentioned at line 85/86 is in the underlying GPS module @Gordon created for Espruino I think?
http://www.espruino.com/modules/GPS.js
Edit:
Removed NoFix as it wasn't actually needed/being used. "line" still seems to keep growing up to 1500+ and then I get the out of memory. -
@Gordon ran the code for a couple of hours and I hit:
{ "time":"18:54:21", "lat":NaN,"lon":NaN,"fix":0,"ERROR: Out of Memory! satellit":3} ERROR: Error processing Serial data handler - removing it. Execution Interrupted during event processing. at line 1 col 18 {console.log(data);if(data.fix>0){consoin function called from system Disabling GPS... Starting GPS...
Is there any way I can trace where the memory is leaking from?
-
I just have to let the timeout run its duration it seems. If I try to clear the timeout when I get a fix it seems to produce an error every other (e.g. all even times/2times) time it searches.
Serial4.setup(9600,{tx:C10,rx:C11}); var SleepDuration = null; var SearchDuration = null; var foundFix = 0; function Start_GPS(){ console.log("Starting GPS..."); //Reset fix found foundFix=0; //After 120 seconds disable the GPS regardless SearchDuration = setTimeout(function (e) { Stop_GPS(); }, 60000); //Set enable pin mode pinMode(A9,'output'); //Set enable pin to high digitalWrite(A9,1); //load gps var gps = require("GPS").connect(Serial4, function(data) { console.log(data); //Check if we have a fix if(data.fix>0) { console.log("Send SMS:" + data.lat + "|" + data.lon); foundFix=1; Stop_GPS(); } }); } function Stop_GPS(){ var gps=""; digitalWrite(A9,0); console.log("Disabling GPS..."); } function onInit(){ //SleepDuration = setTimeout(function (e) {onInit(); }, 360000); console.log("Starting up device & Setting timers..."); setInterval(function (e) { Start_GPS(); }, 360000); Start_GPS(); } onInit();
-
-
Hi All,
I am running the following GPS code:
Serial4.setup(9600,{tx:C10,rx:C11}); var SleepDuration = null; var SearchDuration = null; function Start_GPS(){ console.log("Starting GPS..."); //After 120 seconds disable the GPS regardless SearchDuration = setTimeout(function (e) { Stop_GPS(); }, 60000); //Set enable pin mode pinMode(A9,'output'); //Set enable pin to high digitalWrite(A9,1); //load gps var gps = require("GPS").connect(Serial4, function(data) { console.log(data); //Check if we have a fix if(data.fix>0) { Stop_GPS(); console.log("Send SMS:" + data.lat + "|" + data.lon); } }); } function Stop_GPS(){ clearTimeout(SearchDuration); digitalWrite(A9,0); console.log("Disabling GPS..."); } function onInit(){ SleepDuration = setTimeout(function (e) {onInit(); }, 120000); console.log("Starting up device & Setting timers..."); Start_GPS(); } onInit();
I'm seeing an error popup every so often (not every time the code runs) as shown below:
ERROR: Error processing Serial data handler - removing it. Execution Interrupted during event processing. Uncaught Error: Unknown Timeout at line 1 col 29 {clearTimeout(SearchDuration);digitalWrite(A9,0);console.log... ^ in function "Stop_GPS" called from line 1 col 44 ...a);if(data.fix>0){Stop_GPS();console.log("Send SMS:"+data.la... ^ in function "c" called from line 2 col 81 ...,altitude:parseFloat(a[9])})}c=b.line.indexOf("\n")}} ^ in function called from system Starting up device & Setting timers... Starting GPS...
After leaving the code to execute I am eventually hitting:
"lat":NaN,"lon":NaN,"fix":0,"ERROR: Out of Memory! satellit":0} WARNING: Unable to create string as not enough memory ERROR: Error processing Serial data handler - removing it. Execution Interrupted during event processing. at line 1 col 18 {console.log(data);if(data.fix>0){Stop_in function called from system at line 2 col 81 ...,altitude:parseFloat(a[9])})}c=b.line.indexOf("\n")}} ^ in function called from system Disabling GPS... Starting up device & Setting timers...
And even later on:
Execution Interrupted during event processing. at line 1 col 144 ...tr(3,3)){var a=a.split(","),d=a[2].indexOf("."),e=a[4].index... ^ in function called from system Execution Interrupted during event processing. at line 1 col 144 ...tr(3,3)){var a=a.split(","),d=a[2].indexOf("."),e=a[4].index... ^ in function called from system WARNING: Out of memory while appending to array WARNING: Out of memory while appending to array WARNING: Out of memory while appending to array WARNING: Out of memory while appending to array WARNING: Out of memory while appending to array WARNING: Out of memory while appending to array WARNING: Out of memory while appending to array
Just wondering if anyone can see whats going wrong here? I assume it might be to do with the setTimeouts and then clearing them?
-
Things working a bit nicer now!
var cmd=""; var issued_command=""; //Parse response v2 function parse(buffer){ var line = buffer.toString().substring(0, buffer.length - 1); //Remove anything remotely blank or echoey if(line.length < 2 || line.indexOf(">")===0 || issued_command===line){ return; } issued_command=""; //SMS Received if(line.indexOf("+CMTI")>0){ console.log("SMS Received"); } //Response Received console.log("Parsed: " + line); } //Serial on data v2 Serial4.on('data',function(data){ cmd += data; var id = cmd.indexOf("\n"); while (id>=0){ var line = cmd.substr(0,id); cmd=cmd.substr(id+1); parse(line); id=cmd.indexOf("\n"); } }); function Send_SMS(text) { Start_GSM(); setTimeout(function(){send(text);},10000); } //Start the GSM Module function Start_GSM() { Serial4.setup(9600); console.log("GSM Starting..."); pinMode(C0,"output"); digitalPulse(C0,1,2000); } function Stop_GSM(){ pinMode(C0,"output"); digitalPulse(C0,1,2000); } function send(input){ setTimeout(function(){send_command("AT+CMGS=\"XXXXXXXXXX\"\r");},2000); setTimeout(function(){send_command(input);},3000); setTimeout(function(){send_command("\x1A\r");},3500); setTimeout(function(){Stop_GSM();},10000); } function send_command(command){ //Set the command that we are sending to issue_command for later parse out issued_command=command; //Send the command to serial port connected to GSM Serial4.write(command); //Output what we sent to console console.log("Command Sent:" + command); } function onInit(){ Send_SMS("Heyyyy!"); } onInit();
Results in:
1v66 Copyright 2014 G.Williams >echo(0); GSM Starting... =undefined Command Sent:AT+CMGS="xxxxxx94740" Command Sent:Heyyyy! Command Sent: Parsed: +CMGS: 96 Parsed: OK Parsed: NORMAL POWER DOWN
Now I guess we can do lots with the Parsed responses and I have added in an example of a SMS received which the console will pick up on.
You can add in some error handling and also wait for an OK from an AT send on startup. I think I'll work on the latter next so that I can then kick off the actual SMS sending via callbacks once I'm sure the module is running.
-
This is where I'm at after a refresh.
var cmd=""; //Function handles data coming in from Serial. Serial4.on('data',function (c) { if(c==="\r") { parseResponse(cmd); cmd=""; } cmd+=c; }); //Parse responses on data received on serial function parseResponse(buffer){ if(buffer.length < 2) return; if(buffer.indexOf("ERROR:")>0){ console.log("Error - forcing shutdown"); Stop_GSM(); } else { console.log(buffer); } } function Send_SMS(text) { Start_GSM(); setTimeout(function(){send(text);},10000); } //Start the GSM Module function Start_GSM() { Serial4.setup(9600); console.log("GSM Starting..."); pinMode(C0,"output"); digitalPulse(C0,1,2000); } function Stop_GSM(){ pinMode(C0,"output"); digitalPulse(C0,1,2000); } function send(input){ setTimeout(function(){send_command("AT+CMGS=\"number here\"\r");},2000); setTimeout(function(){send_command(input+"\x1A\r");},3000); setTimeout(function(){Stop_GSM();},10000); } function send_command(command){ //Send the command to serial port connected to GSM Serial4.write(command); } function onInit(){ Send_SMS("Heyyyy!"); } onInit();
For me the timed sending of commands is enough to get things running and sending texts. I just need to add in my GPS code and I'll have a tracker that can sms coords to twilio. My JS skills arent up to doing anything better.
-
@user7143 yeap thats the route you should go down in my opinion.
Typically you will take the response from the on.data, build up a buffer to get a complete command and then check the command to see if it has the required response.
I was part the way implementing that and got confused over how I wanted to go about it. You will see in my original code I had an answer variable which stored the expected response agains the sent command. Note. The answer is not always OK nor is it always the expected answer.
I was hoping to do the check agains the response buffer to see if I got what I wanted in return. If I didnt I would just raise and error and shutdown the module.
There is also the scenario where you have slow response or no initial response. This is why I had the timer implemented into the send command function. This meant that I could repeatedly run the command every few seconds if I didnt get an answer back from the module. There is also the scenario where the command times out, so how long do you want to keep sending a command or waiting for a response until you decide the module is either dead or unresponsive? You can potentially end up in a loop.
As you can see there are a few things to consider and I think I rushed in to it at first without splitting all of the problems down and building out the solution. In my confusion I created quite a mess which I'm now working on to fix. Would be good if you could share your code though might help me get a bit further on my work :)
-
-
-
I'm unsure on how the flora GSM board works @user7143 as the c0 high for 2 seconds is specific to the GSM2 click board I am using. It tells the board to turn on/off. This may not need to be the case in your instance (unsure but worth checking).
-
-
Those extra characters you are seeing seem very similar to the issues I had when I was using GSM modules. The root cause was power. The board needed 5v and also the correct current spikes which I think went up to about 1.4A, ensure your power supply can support this high spike otherwise you will keep getting these messed up chars. Once the power works correctly you often find all the old commands will run through the module also as if they are blocked up so always good to disconnect everything for a few seconds.