Wednesday, September 27, 2017

Ubuntu Keep Process Running After SSH is Terminated

Hello,

Recently I was learning NodeJS and for that I faced an issue with node server. I installed node server via SSH and started server. But as soon as I closed terminal Node server stopped working. But I needed server up and running even if terminal is closed. So after struggle of sometime I found out solution. Here is what we have to do.

Basically when you type command on SSH and start server it runs on the foreground and wait for process to be finished. So as soon as you close terminal foreground process is also terminated and hence your server is stopped.

So in this case you have to run server as background process and if you are using ubuntu you can use nohup  and & to start running process in background hence it will not be terminated once the terminal is closed.

So here is the command you have to follow.

$ nohup "COMMAND" &

Here COMMAND is your command to start the server and since you have mentioned nohup and & it will run the process in background and will not be terminated when SSH is closed.

Thursday, September 7, 2017

jQuery Submit Form with Ajax

Hello,

In this blog we are going to take a look at how we can submit for with Ajax using jQuery.

First of all add jQuery file in your head section of HTML page.

<script src="jquery.min.js"></script>

Now we will have following form.

<form action="">
      <input id="text" autocomplete="off" placeholder="Type here" />
</form>

If you want to submit this form with Ajax using jQuery, first you have to do is add submit event handler.

$(function () {
$('form').submit(function(){
var formData = JSON.stringify($('form').serializeArray());
$.ajax({
type: "POST",
url: "YOUR_API_URL",
data: formData,
success: function(data){

},
failure: function(errMsg) {
}
});
return false;
    });
});

So first we have added submit event handler and used return false so it does refresh the whole page and just use the Ajax request.  Inside event handler we are using HTML 5 FormData to get form data first and then using Ajax request to send data to server in APIs.

Hope this helps you.

Saturday, September 2, 2017

Quick Tips Before You Start Working on IOT Project

Recently me and my team has completed an IOT project where we done GPRS Thermal printer integration with POS and Mobile App. We faced certain issues in project but later on we completed it successfully. Here I am sharing some quick tips before you start working on IOT project.



Readers who are new to the concept of IOT, please read my blog here on IOT.

IOT and IOT Examples, Read here.

1) Understand your IOT device and configure it

As we know IOT is all about connecting machine to Internet. For that you must understand the device and it's configurations. Most of the devices comes with user manual so it would be easy but still sometimes manuals are difficult to understand. For example in our case printer was manufactured in China so we got manuals with some Chinese languages so we had to figure out how it works and do some manual testings to connect printer to internet and get it working. Also you must understand the protocol on which device will work. For example most of the devices use Http protocol but some also work on socket. As per you web server and web services you have to decide protocol to be used.

2) Strictly follow protocol of Device.

This is again and important thing for IOT project. All the devices have some protocol to receive data and to get data back from device. You must follow that. If you don't, then your device will not work properly.

For example in our case if we have to send some data to printer we have to follow following syntax.

"&!*1Order*Item1*Item2#";

So here 1 stands for printer action

if it's 0 that means printer will just print the order and it will be accepted by default.

1 means printer will print it and user have to take action to accept or reject.

So in this case we thought 1 is the serial number so ignored it and printer stopped working.

So it's very important to strictly follow this syntax of devices because IOT devices are very strict in terms of syntax.

3) Have Patience, It will work for sure...

When you are working with hardwares and software together it's always difficult and time consuming. You have to deal with protocols and manual of devices to make it working and for that you should have patience. Also it's testing and development is not easy. First you write some code and trigger some events and then you check if that's working with device or not. So it really needs patience. Do not get frustrated and bang the device. Have patience and keep on working on it. It will work for sure.