Sending text message using AT+command on node.js and serial.js - javascript

I am trying to send SMS AT+commands using node.js and serial.js with below command but it looks like its skipping the senders number, is this a device problem or something is missing with my code? i am using HUAWEI gsm modem attached on my COM2 and my machine is windows 7.
var SerialPort = require('serialport');
var port = new SerialPort('COM2', {
baudrate: 9600,
dataBits: 8,
parity: 'none'
});
console.log('port is now open');
port.on("open", function () {
console.log('Serial communication open');
port.write("AT");
port.write('\r');
port.on('data', function(data) {
console.log("Received data: " + data);
});
gsm_message_sending(port, "test2", "89410238(example only)");
});
function gsm_message_sending(serial, phone_no, message) {
serial.write("AT+CMGF=1");
serial.write('\r');
serial.write("AT+CMGS=\"" + phone_no + "\"");
serial.write('\r');
serial.write(message);
serial.write(Buffer([0x1A]));
serial.write('^z');
}
I tried to change the line using below code but still the same output.
serial.write("AT+CMGS=\"");
serial.write(phone_no);
serial.write('"')
My console returns below
Any advice would be great! thanks in advance!

I haven't tried your example but, looking at the code, you are calling:
gsm_message_sending(port, "test2", "89410238(example only)");
i.e. the parameters are in the wrong order, it should be:
gsm_message_sending(serial, phone_no, message)

Related

Session is not open when connecting to autobahn js

I'm having trouble while developing chat-like feature to my socket server.
First let me give you a little bit of my code:
document.conn = new ab.Session('ws://127.0.0.1:8090',
function () {
console.log('AB:Connected!');
conn.subscribe('room_1', function (topic, data) {
console.log('New message published to room "' + topic + '" : ' + data.content + ' by:' );
console.log(data);
});
},
function () {
console.warn('WebSocket connection closed');
},
{'skipSubprotocolCheck': true}
);
Currently it's attached to document just to try it out, the error I'm getting is as follows:
"Session not open"
I'm a bit confused about this error and it's origin, should I somehow define the connection?
do you start your socket server through cmd.exe ?
you need to use this command to start the server:
php c://wamp64/www/yourproject/bin/push-server.php

I'm trying to publish a message of a Tizen based app on ros using rosbridge and i get an error

as the title says, I'm trying to publish a message on ros using rosbridge, because my app is written in javascript. Basically i want to cast a stream of heart rate data on a pc running ros to so some elaboration. The app is running on a Tizen based smartwatch. If i try to publish geometry messages, like the device orientation, i have no problem and they are published on ros. I tried the sensor message type (channelfloat32 in particular) to cast the stream of the heart rate with no success. I investigated on the type of the data coming out from the sensor and i discovered that is a number type data of javascript.
So i used the standard message type (Float64 in particular because, as far as i know based on some searching, apparently javascript uses only this type for numbers) with no success again.
Maybe i could cast the variable or change its type, but i don't know if this could be a possible solution and i really don't know how to do it, maybe i only have to change the type of the ros message.
As you can see from my previous questions I'm very new to coding and I'm again on the same project.
Thank you in advance for your help!
Marco
The code is below:
document.addEventListener('tizenhwkey', function(e) {
if(e.keyName === "back")
window.webapis.motion.stop("HRM");
tizen.application.getCurrentApplication().exit();
});
function Connect(){
var ip;
var connection=false;
if (document.getElementById("ip").value==="")
{
ip="10.42.0.1";
}
else
{
ip=document.getElementById("ip").value;
}
var ros = new ROSLIB.Ros({
url : 'ws://' + ip +':9090'
});
ros.on('connection', function() {
connection=true;
document.getElementById("Connection_status").setAttribute("color","green");
document.getElementById("Connection_status").innerHTML = 'Connected';
tizen.power.request("SCREEN", "SCREEN_DIM");
});
ros.on('error', function(error) {
document.getElementById("Connection_status").setAttribute("color","orange");
document.getElementById("Connection_status").innerHTML = 'Error';
});
ros.on('close', function() {
document.getElementById("Connection_status").setAttribute("color","red");
document.getElementById("Connection_status").innerHTML = 'Unconnected';
connection=false;
tizen.power.release("SCREEN");
});
var RatePub = new ROSLIB.Topic({
ros : ros,
name : '/HeartRateData',
messageType : 'std_msgs/Float64'
});
window.webapis.motion.start("HRM", onchangedCB);
function onchangedCB(hrmInfo)
{
var data = hrmInfo.heartRate;
document.getElementById("mytext").innerHTML = 'Heart Rate= ' + data + ' bpm';
var Float64 = new ROSLIB.Message({
data:[data]
});
if(connection===true)
{
RatePub.publish(Float64);
}
else
{
document.getElementById("mytext").innerHTML = 'Heart Rate= 0 bpm';
}
}}
If you are reading HRM data from Tizen wearable device you may use tizen.humanactivitymonitor of Human Activity Monitor API Instead of using window.webapis.motion
Rather using
window.webapis.motion.start("HRM", onchangedCB);
function onchangedCB(hrmInfo) {
var data = hrmInfo.heartRate;
document.getElementById("mytext").innerHTML = 'Heart Rate= ' + data + ' bpm';
...
..
}
You may try
var dataCount = 0;
function onsuccessCB(hrmInfo)
{
console.log("Heart Rate: " + hrmInfo.heartRate);
console.log("Peak-to-peak interval: " + hrmInfo.rRInterval + " milliseconds");
dataCount++;
...
..
if (dataCount > 10){
/* Stop the sensor after detecting a few changes */
tizen.humanactivitymonitor.stop("HRM");
}
}
tizen.humanactivitymonitor.start("HRM", onsuccessCB);
And add the necessary privileges in config.xml file
<tizen:privilege name="http://tizen.org/privilege/healthinfo"/>
<tizen:privilege name="http://tizen.org/privilege/power"/>
According to the Tizen API reference datatype of the heartRate is long.
Please Check the Tizen Human Activity Monitor Guide and Tizen API reference for details implementation.

CasperJS - Screen capture returns black image & test case does not find element when target url is not localhost

I am using CasperJs along with Phantomjs 1.9.8. I am testing a site which uses windows authentication. I am testing a version which is deployed on a remote server and locally.
Here is the test case.
var baseUrl = "http://SNG09034236:9999"; //For testing app on remote server
//var baseUrl = "http://localhost:9999"; //For testing app locally
casper.options.viewportSize = {
width: 1024,
height: 800
}
casper.pageSetting = {userName: 'myuid', password:pwd};
casper.options.waitTimeout = 5000;
casper.on('resource.requested', function(requestData, networkRequest) {
//console.log('Request (#' + requestData.id + '): ' + JSON.stringify(requestData) + "\n");
});
casper.on("resource.received", function(response){
// console.log('Response (#' + response.id + ', stage "' + response.stage + '"): ' + JSON.stringify(response) + "\n");
});
casper.test.begin('Connecting to application', function suite(test) {
casper.start(baseUrl, function() {
document.querySelector("body").style.height = "700px";
this.echo("TITLE : ====> " + this.getTitle());
this.captureSelector('c:\\temp\\myImage.png', 'html');
})
.then(function(){
test.assertTitle("My app", "Title is correct");
})
.waitForSelector("#showUser",
function success() {
test.assertExists("#showUser", "Shadow button found");
this.click("#showUser");
},
function fail() {
console.log('Shadow button NOT found');
test.assertExists("#showUser");
})
.waitForSelector("#show-window-body",
function success() {
test.assertExists("#show-window-body", "Show div found");
this.click("#show-window-body");
},
function fail() {
test.assertExists("#show-window-body");
})
.waitForSelector("input[name='search_user-inputEl']",
function success() {
test.assertExists("input[name='search_user-inputEl']", "Show text box found");
this.click("input[name='search_user-inputEl']");
this.sendKeys('#search_user-inputEl', 'tomjspn3');
},
function fail() {
test.assertExists("input[name='search_user-inputEl']");
})
.waitForSelector("li",
function success() {
test.assertExists("li", "User found");
this.click("li");
},
function fail() {
test.assertExists("li", "User NOT found");
})
.run(function() {
casper.echo("TESTS COMPLETED");
casper.exit();
});
});
Issues:
this.captureSelector('c:\\temp\\myImage.png', 'html'); always returns a black image file (for site hoested locally and remotely ). But if test another site (google.com etc), I get the correct screenshot.
In the test case I am searching for showUser div. When the run the test case targeting a site which is hosted on local box, everything works fine and when I run same test case by changing the URL to a remote server, system cannot find the showUser div and does not produce any result.
Actually after adding the various hooks I can see following error when connecting to remote site:
Response (#1, stage "end"): {"contentType":null,"headers":[],"id":1,"redirectUR
":null,"stage":"end","status":401,"statusText":"Authorization Required","time":
2015-12-03T17:26:15.691Z","url":"http://SNG09034236:9999/"}
ResourceError: {
"errorCode": 5,
"errorString": "Operation canceled",
"id": 0,
"url": "http://SNG09034236:9999/"
}
I have also changed casper.pageSetting to casper.options.pageSetting

iceCandidate got failed for webRTC in Mozilla Firefox

I did sample application for Video communication in webRTC.Its working fine for Chrome but in Firefox its giving iceCandidatefailed error. Can you please suggest me. This is the code having some problem.
Thanks in advance.
function onicecandidate(iceCandidate) {
debugger;
console.log("ice candidate send to room ", iceCandidate);
// send candidates to other guy
if (!peerConnection || !event || !event.candidate) return;
var candidate = event.candidate;
debugger;
var data = {
'type': 'candidate', 'label':candidate.sdpMLineIndex, 'sdpMid':candidate.sdpMid, 'candidate':candidate.candidate
};
socket.emit('message', data);
};

Autobahn.js - subscribe doesn't work with websockets

I'm using Ratchet WebSockets and Autobahn.js for two-way client-server communication. I've installed everything, opened the ports, it's been weeks (yes, literally weeks) and it still doesn't work. I think I've narrowed it down to Autobahn's subscribe method not working correctly.
What I'm using is a slight modification of the example code found here:
http://socketo.me/docs/push
Here is my client code:
<script>
window.define = function(factory) {
try{ delete window.define; } catch(e){ window.define = void 0; } // IE
window.when = factory();
};
window.define.amd = {};
</script>
<script src="/apps/scripts/when.js"></script>
<script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script>
<script>
var conn = new ab.Session(
'ws://light-speed-games.com:8080' // The host (our Ratchet WebSocket server) to connect to
, function() { // Once the connection has been established
console.log('Connection established.');
conn.subscribe('kittensCategory', function(topic, data) {
// This is where you would add the new article to the DOM (beyond the scope of this tutorial)
console.log('New article published to category "' + topic + '" : ' + data.title);
});
}
, function() { // When the connection is closed
console.warn('WebSocket connection closed');
}
, { // Additional parameters, we're ignoring the WAMP sub-protocol for older browsers
'skipSubprotocolCheck': true
}
);
</script>
I believe the problem lies here:
function() { // Once the connection has been established
console.log('Connection established.');
conn.subscribe('kittensCategory', function(topic, data) {
// This is where you would add the new article to the DOM (beyond the scope of this tutorial)
console.log('New article published to category "' + topic + '" : ' + data.title);
});
}
The line console.log('Connection established.'); does its job - it logs its message in the console. However, the conn.subscribe method does nothing. It doesn't matter if I change kittensCategory to any other string, it still does nothing. But kittensCategory is the only thing that makes sense here (see Ratchet's example code through the link above).
Any ideas?
EDIT:
This is the output of ab.debug:
WAMP Connect autobahn.min.js:69
ws://light-speed-games.com:8080 autobahn.min.js:69
wamp autobahn.min.js:69
WS Receive autobahn.min.js:64
ws://light-speed-games.com:8080 [null] autobahn.min.js:64
1 autobahn.min.js:64
[0,"52cbe9d97fda2",1,"Ratchet\/0.3"] autobahn.min.js:64
WAMP Welcome autobahn.min.js:67
ws://light-speed-games.com:8080 [52cbe9d97fda2] autobahn.min.js:67
1 autobahn.min.js:67
Ratchet/0.3 autobahn.min.js:67
Connection established. client.php:15
WAMP Subscribe autobahn.min.js:74
ws://light-speed-games.com:8080 [52cbe9d97fda2] autobahn.min.js:74
kittensCategory autobahn.min.js:74
function (topic, data) {
// This is where you would add the new article to the DOM (beyond the scope of this tutorial)
console.log('New article published to category "' + topic + '" : ' + data.title);
} autobahn.min.js:74
WS Send autobahn.min.js:72
ws://light-speed-games.com:8080 [52cbe9d97fda2] autobahn.min.js:72
1 autobahn.min.js:72
[5,"kittensCategory"]

Categories