Saturday, March 29, 2014

Tkinter GUI ApplicationDevelopment HOTSHOT


Tkinter GUI ApplicationDevelopment HOTSHOT

Develop exciting and engaging GUI applications in Python and Tkinter by working on 10 real-world applications
Overview
  • Develop 10 real GUI applications using procedural and object-oriented styles
  • Write network programs, database-driven programs, multi-threaded programs and more with Tkinter
  • A practical guide to discover the best practices involved in writing GUI applications
In Detail
Tkinter is the built-in GUI package that comes with standard python distributions. This means it is easy to get started right away, without any extra installation or configuration. Tkinter's strength lies in its simplicity of use and its intuitive nature which makes it suited for programmers and non-programmers alike. Once you get started, you will be surprised to see how a few lines of code can produce powerful GUI applications.
Tkinter GUI Application Development Hotshot helps you learn the art of GUI programming - building real-world, productive and fun applications like text editor, drum machine, game of chess, media player, drawing application and many more. Each subsequent project builds on the skills acquired in the previous project. Also, learn to write multi-threaded and multi layered applications using Tkinter. Get to know modern best practices involved in writing GUI programs. Tkinter GUI Application Development Hotshot comes with a rich source of sample codes that you can use in your own projects in any discipline of your choice.
Starting with a high level overview of Tkinter that covers the most important concepts involved in writing a GUI application, the book then takes you through a series of real world projects of increasing complexity, developing one project per chapter. After you have developed five full projects, the book provides you with some bare-bone skeleton codes for a few functional but incomplete projects, challenging you to put your skills to test by completing them.
Finally, you are provided with tips for writing reusable, scalable, and quality GUI code for larger projects. The appendices provide a quick reference sheet for Tkinter.
What you will learn from this book
  • Structure your programs in the model-view framework
  • Persist your application data with object serialization
  • Work with external libraries and Tkinter extensions
  • Write multi-threaded GUI programs
  • Re-factor code at every stage of application development
  • Integrate your GUI applications to backend database
  • Use networking with your Tkinter program
  • Apply Internationalization to your GUI applications
  • Develop a GUI program framework for maximum code reuse and rapid application development
Approach
Practical, real-world example projects. Start with the topics that grab your attention or work through each project in sequence.
Who this book is written for
If you have just started with GUI programming, this book is ideal for you. This book is also great if you are an experienced software developer, scientist, researcher, engineer, student, or hobbyist.

Thursday, March 27, 2014

Getting Started with JavaFX Embedded on a Raspberry Pi

Learn how to quickly get a JavaFX simple application up and running on a Raspberry Pi development board.

Java 8 on the Raspberry Pi

Watch how a full version of Java SE & JavaFX run on Raspberry Pi.

Tuesday, March 25, 2014

Speaking JavaScript

Speaking JavaScript

Speaking JavaScript

Like it or not, Java Script is everywhere these days—from browser to server to mobile—and now you, too, need to learn the language or dive deeper than you have. This concise book guides you into and through JavaScript, written by a veteran programmer who once found himself in the same position.
Speaking JavaScript helps you approach the language with four standalone sections. First, a quick-start guide teaches you just enough of the language to help you be productive right away. More experienced JavaScript programmers will find a complete and easy-to-read reference that covers each language feature in depth. Complete contents include:
  • JavaScript quick start: Familiar with object-oriented programming? This part helps you learn JavaScript quickly and properly.
  • JavaScript in depth: Learn details of ECMAScript 5, from syntax, variables, functions, and object-oriented programming to regular expressions and JSON with lots of examples. Pick a topic and jump in.
  • Background: Understand JavaScript’s history and its relationship with other programming languages.
  • Tips, tools, and libraries: Survey existing style guides, best practices, advanced techniques, module systems, package managers, build tools, and learning resources.
"The most concise and yet complete JavaScript book written to date for the initiated programmer."

—Cody Lindley, front-end engineer, author of JavaScript Enlightenment

Monday, March 24, 2014

Bi-directional control between Raspberry Pi + Node.js + Arduino

This example show how to pass data between Node.js client, Node.js server running on Raspberry Pi, and Arduino, bi-directionally. A Arduino Esplora is connected to Raspberry Pi, with Node.js running up a simple web app. Client can load the web app with Pi's IP and port 8080.

the tablet in the video for demo only.

From Node.js clients to server to Arduino:
- User can toggle the button to set Arduino LED ON/OFF.
- User can select color from of Arduino LCD color.

From Arduino to Node.js server to clients.
- When the Slider on Esplora changed, the setting will be sent to Node.js server to clients' progress bar on page.


Node.js code, app.js
var app = require('http').createServer(handler), 
    io = require('socket.io').listen(app), 
    fs = require('fs'),
    os = require('os'),
    sp = require("serialport");
    
//All clients have a common status
var commonStatus = 'ON';
var commonColor = 0xffffff;
var commonSldValue = 0;
  
//init for SerialPort connected to Arduino
var SerialPort = sp.SerialPort
var serialPort = new SerialPort('/dev/ttyACM0', 
    {   baudrate: 9600,
        dataBits: 8,
        parity: 'none',
        stopBits: 1,
        flowControl: false
    });
    
var receivedData = "";
    
serialPort.on("open", function () {
    console.log('serialPort open');
    serialPort.write("LEDOFF\n");
    
    //handle data receive from Arduino
    serialPort.on('data', function(data) {
  receivedData += data.toString();
  if (receivedData.indexOf("SLD#") >= 0 
   && receivedData.indexOf("\n") >= 0) {
    
   sldValue = receivedData.substring(
    receivedData.indexOf("SLD#")+4, 
    receivedData.indexOf("\n"));
    
   receivedData = "";
   
   if ((sldValue.length == 1)
    || (sldValue.length == 2)){
    commonSldValue = parseInt("0x"+sldValue); 
    io.sockets.emit('update slider', 
       { value: commonSldValue});
    console.log('update slider: ' + commonSldValue);
   } 
  }
 });
    
});
    
//Display my IP
var networkInterfaces=os.networkInterfaces();

for (var interface in networkInterfaces) {
    
    networkInterfaces[interface].forEach(
        function(details){
            
            if (details.family=='IPv4' 
                && details.internal==false) {
                    console.log(interface, details.address);  
        }
    });
}

app.listen(8080);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.sockets.on('connection', function (socket) {
    
    //Send client with his socket id
    socket.emit('your id', 
        { id: socket.id});
    
    //Info all clients a new client caaonnected
    io.sockets.emit('on connection', 
        { client: socket.id,
          clientCount: io.sockets.clients().length,
        });
        
    //Set the current common status to the new client
    socket.emit('ack button status', { status: commonStatus });
    socket.emit('ack color', { color: commonColor });
    socket.emit('update slider', { value: commonSldValue});
    
    socket.on('button update event', function (data) {
        console.log(data.status);
        
        //acknowledge with inverted status, 
        //to toggle button text in client
        if(data.status == 'ON'){
            console.log("ON->OFF");
            commonStatus = 'OFF';
            serialPort.write("LEDON\n");
        }else{
            console.log("OFF->ON");
            commonStatus = 'ON';
            serialPort.write("LEDOFF\n");
        }
        io.sockets.emit('ack button status', 
            { status: commonStatus,
              by: socket.id
            });
    });
    
    socket.on('update color', function (data) {
  commonColor = data.color;
  console.log("set color: " + commonColor);
  var stringColorHex = "COL" + commonColor.toString(16);
  console.log("stringColorHex: " + stringColorHex);
  
  serialPort.write(stringColorHex + "\n");
  
  io.sockets.emit('ack color', 
   { color: data.color,
     by: socket.id
   });
 });
    
    //Info all clients if this client disconnect
    socket.on('disconnect', function () {
        io.sockets.emit('on disconnect', 
            { client: socket.id,
              clientCount: io.sockets.clients().length-1,
            });
    });
});

index.html
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, user-scalable=no">
<head></head>
<body>
<hi>Test Node.js with socket.io</hi>
<form action="">
<input type="button" id="buttonToggle" value="ON" style="color:blue"
       onclick="toggle(this);">
</form>
<br/>
Select color: <br/>
<input id="colorpick" type="color" name="favcolor" 
 onchange="JavaScript:colorchanged()"><br>
<br/>
<progress id="progressbar" max="255"><span>0</span>%</progress>


<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect(document.location.href);
var myId;

socket.on('update slider', function (data) {
    console.log("update slider: " + data.value);
    document.getElementById("progressbar").value = data.value;
});

socket.on('on connection', function (data) {
    console.log("on connection: " + data.client);
    console.log("Number of client connected: " + data.clientCount);
});

socket.on('on disconnect',function(data) {
    console.log("on disconnect: " + data.client);
    console.log("Number of client connected: " + data.clientCount);
});

socket.on('your id',function(data) {
    console.log("your id: " + data.id);
    myId = data.id;
});

socket.on('ack button status', function (data) {
    console.log("status: " + data.status);
    
    if(myId==data.by){
        console.log("by YOU");
    }else{
        console.log("by: " + data.by);
    }
    
    if(data.status =='ON'){
        document.getElementById("buttonToggle").value="ON";
    }else{
        document.getElementById("buttonToggle").value="OFF";
    }
});

socket.on('ack color', function (data) {
    console.log("ack color: " + data.color);
    document.body.style.background = data.color;
    if(myId==data.by){
        console.log("by YOU");
    }else{
        console.log("by: " + data.by);
    }
});

function toggle(button)
{
 if(document.getElementById("buttonToggle").value=="OFF"){
  socket.emit('button update event', { status: 'OFF' });
 }
 else if(document.getElementById("buttonToggle").value=="ON"){
  socket.emit('button update event', { status: 'ON' });
 }
}

function colorchanged()
{
 //console.log("colorchanged()");
 var colorval = document.getElementById("colorpick").value;
 console.log("colorchanged(): " + colorval);
 //document.body.style.background = colorval;
 socket.emit('update color', { color: colorval });
}

</script>

</body>
</html>

Arduino code:
#include <Esplora.h>
#include <TFT.h>
#include <SPI.h>

int MAX_CMD_LENGTH = 10;
char cmd[10];
int cmdIndex;
char incomingByte;

int prevSlider = 0;

void setup() {
  
    EsploraTFT.begin();  
    EsploraTFT.background(0,0,0);
    EsploraTFT.stroke(255,255,255);  //preset stroke color
     
    //Setup Serial Port with baud rate of 9600
    Serial.begin(9600);
    
    //indicate start
    Esplora.writeRGB(255, 255, 255);
    delay(250);
    Esplora.writeRGB(0, 0, 0);
    
    cmdIndex = 0;
    
}
 
void loop() {
    
    if (incomingByte=Serial.available()>0) {
      
      char byteIn = Serial.read();
      cmd[cmdIndex] = byteIn;
      
      if(byteIn=='\n'){
        //command finished
        cmd[cmdIndex] = '\0';
        //Serial.println(cmd);
        cmdIndex = 0;
        
        String stringCmd = String(cmd);
        
        if(strcmp(cmd, "LEDON")  == 0){
          //Serial.println("Command received: LEDON");
          Esplora.writeRGB(255, 255, 255);
        }else if (strcmp(cmd, "LEDOFF")  == 0) {
          //Serial.println("Command received: LEDOFF");
          Esplora.writeRGB(0, 0, 0);
        }else if(stringCmd.substring(0,4)="COL#"){
          //Serial.println("Command received: COL#");
          if(stringCmd.length()==10){
            char * pEnd;
            long int rgb = strtol(&cmd[4], &pEnd, 16);
            int r = (rgb & 0xff0000) >> 16;
            int g = (rgb & 0xff00) >> 8;
            int b = rgb & 0xff;
            //Serial.println(r);
            //Serial.println(g);
            //Serial.println(b);
            EsploraTFT.background(b,g,r);
          }
        }else{
          //Serial.println("Command received: unknown!");
        }
        
      }else{
        if(cmdIndex++ >= MAX_CMD_LENGTH){
          cmdIndex = 0;
        }
      }
    }
    
    //Read Slider
    int slider = Esplora.readSlider();
    //convert slider value from [0-1023] to [0x00-0xFF]
    slider = slider>>2 & 0xff;
    
    if(slider!=prevSlider){
      prevSlider = slider;
      
      String stringSlider = String(slider, HEX);
      Serial.println("SLD#" + stringSlider +"\n");
    }
    
}

Cross post with Arduino-er, same code run on PC running Ubuntu Linux.

Saturday, March 22, 2014

Video playlist - IoT and Java

Playlist for IoT and Java, include the following title:
  • Introduction to the Internet of Things
    What are some of the applications and devices in IoT space? In which industries are we seeing innovations? What kind of hardware can you use? What do you need to create your own project?
  • Java and the Internet of Things
    An Overview of the Java Embedded Platform, including Java SE Embedded, Java ME Embedded, and more.
  • Introduction to Raspberry Pi
    What is the Raspberry Pi? What do you need to install?
  • Java Embedded and Raspberry Pi - Part 1
  • Java Embedded and Raspberry Pi - Part 2
  • Gemalto Board Demo
    Build a Gemalto app and submit it to IoT Developer Challenge 

Enter the IoT Developer Challenge by May 30th, 2014 www.java.net/challenge.

Thursday, March 20, 2014

Raspberry Pi Starter Pack


Raspberry Pi Starter Pack
  • 512MB Raspberry Pi Model B with 8GB pre-loaded SD card
  • Adafruit Pi Cobbler Breakout Kit and Acrylic Case
  • 2A USB Wall Charger, USB Cable and HDMI Cable
  • Deluxe full-sized Breadboard and Jumper Wires
  • Mintronics Survival Pack Guts with 60+ Components -Includes Resistors, Capacitors, and More
By now you've probably heard of the Raspberry Pi -- the credit card-sized computer that runs Linux. It has many of the capabilities of a traditional PC and can be used for word processing, spreadsheets, and games. It can even play high-definition video and hook up to a TV or monitor. The Pi has been called many things (cheap, small, hackable, educational), but people seem to shy away from calling it "plug and play." That's because the Pi is not a consumer device as such, even though it's pretty easy to get something up and running on you TV. That's where our Raspberry Pi Starter Kit comes in: we've sourced all the proper peripherals and add-ons to get you up and running in all sorts of maker applications. The board was developed by the Raspberry Pi Foundation with the intention of bringing low cost, easy to program computers to young people all over the world. Once you get the "Raspbian" operating system loaded onto the kit's SD card, you can start programming right out of the box. The kit's selection of prototyping tools will also help you use the input and output capabilities of the Pi from your onboard programs. You'll still need to add your own USB keyboard and mouse, but otherwise, the Raspberry Pi Starter Kit includes all of the necessary cables (USB and HDMI), Adafruit's Cobbler GPIO (General Purpose Input/Output) breakout, a custom enclosure, a 8GB SD card, a breadboard for electronics prototyping, and plenty of common components to get you started. Includes a print copy of the Getting Started with Raspberry Pi book by Shawn Wallace and Matt Richardson.

Node.js+socket.io+serialport = web app to control Pi connected Arduino

This is a example to implement a web app with Node.js running on Raspberry Pi, to receive command from client, and control connected Arduino Esplora's LED. All clients share a common hardware: when a client toggle the LED, all clients will be updated accordingly.


This example should be run on any other Node.js supported platform, with changing SerialPort name. The tablet is used to log-in Raspberry Pi to start the app, for demonstrate only, not a part of the example.

You have to install socket.io and serialport modules for Node.js:
$ npm install socket.io
$ npm install serialport

app.js
var app = require('http').createServer(handler), 
    io = require('socket.io').listen(app), 
    fs = require('fs'),
    os = require('os'),
    sp = require("serialport");
  
//init for SerialPort connected to Arduino
var SerialPort = sp.SerialPort
var serialPort = new SerialPort('/dev/ttyACM0', 
    {   baudrate: 9600,
        dataBits: 8,
        parity: 'none',
        stopBits: 1,
        flowControl: false
    });
    
serialPort.on("open", function () {
    console.log('serialPort open');
    serialPort.write("LEDOFF\n");
});
    
//Display my IP
var networkInterfaces=os.networkInterfaces();

for (var interface in networkInterfaces) {
    
    networkInterfaces[interface].forEach(
        function(details){
            
            if (details.family=='IPv4' 
                && details.internal==false) {
                    console.log(interface, details.address);  
        }
    });
}

//All clients have a common status
var commonStatus = 'ON';

app.listen(8080);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.sockets.on('connection', function (socket) {
    
    //Send client with his socket id
    socket.emit('your id', 
        { id: socket.id});
    
    //Info all clients a new client caaonnected
    io.sockets.emit('on connection', 
        { client: socket.id,
          clientCount: io.sockets.clients().length,
        });
        
    //Set the current common status to the new client
    socket.emit('ack button status', { status: commonStatus });
    
    socket.on('button update event', function (data) {
        console.log(data.status);
        
        //acknowledge with inverted status, 
        //to toggle button text in client
        if(data.status == 'ON'){
            console.log("ON->OFF");
            commonStatus = 'OFF';
            serialPort.write("LEDON\n");
        }else{
            console.log("OFF->ON");
            commonStatus = 'ON';
            serialPort.write("LEDOFF\n");
        }
        io.sockets.emit('ack button status', 
            { status: commonStatus,
              by: socket.id
            });
    });
    
    //Info all clients if this client disconnect
    socket.on('disconnect', function () {
        io.sockets.emit('on disconnect', 
            { client: socket.id,
              clientCount: io.sockets.clients().length-1,
            });
    });
});

index.html
<html>
<meta name="viewport" content="width=device-width, user-scalable=no">
<head></head>
<body>
<hi>Test Node.js with socket.io</hi>
<form action="">
<input type="button" id="buttonToggle" value="ON" style="color:blue"
       onclick="toggle(this);">
</form>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect(document.location.href);
var myId;

socket.on('on connection', function (data) {
    console.log("on connection: " + data.client);
    console.log("Number of client connected: " + data.clientCount);
});

socket.on('on disconnect',function(data) {
    console.log("on disconnect: " + data.client);
    console.log("Number of client connected: " + data.clientCount);
});

socket.on('your id',function(data) {
    console.log("your id: " + data.id);
    myId = data.id;
});

socket.on('ack button status', function (data) {
    console.log("status: " + data.status);
    
    if(myId==data.by){
        console.log("by YOU");
    }else{
        console.log("by: " + data.by);
    }
    
    if(data.status =='ON'){
        document.getElementById("buttonToggle").value="ON";
    }else{
        document.getElementById("buttonToggle").value="OFF";
    }
});

function toggle(button)
{
 if(document.getElementById("buttonToggle").value=="OFF"){
  socket.emit('button update event', { status: 'OFF' });
 }
 else if(document.getElementById("buttonToggle").value=="ON"){
  socket.emit('button update event', { status: 'ON' });
 }
}
</script>

</body>
</html>

Arduino code
#include <Esplora.h>
#include <TFT.h>
#include <SPI.h>

int MAX_CMD_LENGTH = 10;
char cmd[10];
int cmdIndex;
char incomingByte;

void setup() {
  
    EsploraTFT.begin();  
    EsploraTFT.background(0,0,0);
    EsploraTFT.stroke(255,255,255);  //preset stroke color
     
    //Setup Serial Port with baud rate of 9600
    Serial.begin(9600);
    
    //indicate start
    Esplora.writeRGB(255, 255, 255);
    delay(250);
    Esplora.writeRGB(0, 0, 0);
    
    cmdIndex = 0;
    
}
 
void loop() {
    
    if (incomingByte=Serial.available()>0) {
      
      char byteIn = Serial.read();
      cmd[cmdIndex] = byteIn;
      
      if(byteIn=='\n'){
        //command finished
        cmd[cmdIndex] = '\0';
        Serial.println(cmd);
        cmdIndex = 0;
        
        if(strcmp(cmd, "LEDON")  == 0){
          Serial.println("Command received: LEDON");
          Esplora.writeRGB(255, 255, 255);
        }else if (strcmp(cmd, "LEDOFF")  == 0) {
          Serial.println("Command received: LEDOFF");
          Esplora.writeRGB(0, 0, 0);
        }else{
          Serial.println("Command received: unknown!");
        }
        
      }else{
        if(cmdIndex++ >= MAX_CMD_LENGTH){
          cmdIndex = 0;
        }
      }
    }
    
}

Cross post with Arduino-er

Next: Bi-directional control between Raspberry Pi + Node.js + Arduino

Wednesday, March 19, 2014

Build GTK+ Project using Code::Blocks on Raspberry Pi

In the Project Wizard of Code::Blocks, GTK+ Project is supported. But it cannot be compiled, because of lack of options for GTK+.

Prepare:

Create GTK+ Project with File > New > Project...
Select GTK+ project, with the auto-generated source code.

Set Build Options:
Project > Build options...
- In Compiler settings > Other options, add `pkg-config --cflags gtk+-3.0`.

Compiler settings > Other options
- In Linker settings > Other linker options, add `pkg-config --libs gtk+-3.0`.

Linker settings > Other linker options
Build and Run:
helloGtk

Install Code::Blocks on Raspberry Pi

Code::Blocks is a open source, cross platform, free C, C++ and Fortran IDE.

To install Code::Blocks on Raspberry Pi, enter the command:
sudo apt-get install codeblocks

Current installed version is 10.05.
Code::Blocks
Code::Blocks installed on Raspberry Pi
Once installed, Code::Blocks can be start by enter the command:
codeblocks

Or click Start in X-Window > Programming > Code::Blocks IDE


Node Security

Node Security

Node Security

Take a deep dive into the world of securing your Node applications with Node Security
Overview
  • Examine security features and vulnerabilities within JavaScript
  • Explore the Node platform, including the event-loop and core modules
  • Solve common security problems with available npm modules
In Detail
Node.js is a fast-growing platform for building server applications using JavaScript. Now that it is being more widely used in production settings, Node applications will start to be specifically targeted for security vulnerabilities. Protecting your users will require an understanding of attack vectors unique to Node, as well as shared with other web applications.
To secure Node.js applications, we’ll start by helping you delve into the building blocks that make up typical Node applications. By understanding all the layers that you are building on top of, you can write code defensively and securely. In doing so, you will be able to protect your user's data and your infrastructure, while still using the rock-star technology behind Node.js.
Teaching you how to secure your Node applications by learning about each of the layers you will be building on top of; starting with JavaScript itself, then the Node platform, and finally the npm module ecosystem. By starting with JavaScript, you will learn what to avoid and what to embrace. Next, we will explain the Node platform, including its unique architecture and core modules, so you know how things work under the hood. Finally, we will introduce the rich ecosystem of npm modules, including modules to help you solve the common security problems you might face. Through our handy tutorials, you will be able to write secure Node.js applications, ones that will remain online under pressure and be able to weather the most common attacks that face web applications today.
What you will learn from this book
  • Master the origins of the Node.js and npm projects
  • Understand the architecture, including the event-loop and asynchronous I/O
  • Delve into the key aspects of avoiding some common pitfalls of JavaScript development
  • Incorporate ES5's security improvements, including strict-mode
  • Add static code analysis and the code-quality it promotes
  • Explore the basics of proper error-handling within Node applications
  • Understand the architecture of Express and Connect
  • Adapt common authentication and authorization schemes
Approach
A practical and fast-paced guide that will give you all the information you need to secure your Node applications.
Who this book is written for
If you are a developer who wishes to secure your Node applications, whether you are already using Node Security in production, or are considering using it for your next project, then this book will enable you to ensure security of your applications. An understanding of JavaScript is a prerequisite, and some experience with Node is recommended, though not required.

C++ Application Development with Code::Blocks

C++ Application Development with Code::Blocks

C++ Application Development with Code::Blocks

Develop advanced applications with Code::Blocks quickly and efficiently with this concise, hands-on guide
Overview
  • Successfully install and configure Code::Blocks for C++ development
  • Perform rapid application development with Code::Blocks
  • Work with advanced C++ features including code debugging and GUI toolkits
In Detail
Code::Blocks is a free C++ IDE designed to meet the extensive demands of C++ developers. Code::Blocks is very extensible and can be easily configured to maintain a consistent look and feel in your application across multiple platforms. If you are looking to develop cross-platform applications using C++, then this book is for you.
This book provides practical explanations for application development with C++ and Code::Blocks. You will get to grips with the many aspects of professional application development with the help of real-life examples. As you proceed through the chapters, you will see yourself effectively working with and implementing advanced C++ features in your application.
The book begins with an introduction to Code::Blocks and detailed instructions on how to install and configure it. You are then introduced to the process of application development with the help of real-life examples. Throughout the course of the book, you will learn how to develop GUI-based applications painlessly. The book also places special emphasis on debugging the application. The later sections take a closer look at using third party C++ libraries and how to implement wxWidgets to develop cross-platform applications. By the end of this book, you will know everything you need to know about C++ application development with Code::Blocks.
What you will learn from this book
  • Install and configure Code::Blocks
  • Develop console-based C++ applications
  • Learn about Windows application development
  • Understand the role of GUI toolkits
  • Implement advanced Code::Block features
Approach
This is a comprehensive tutorial with step-by-step instructions on how to develop applications with Code::Blocks.
Who this book is written for
This book is for C++ developers who wish to use Code::Blocks to create applications with a consistent look and feel across multiple platforms. This book assumes that you are familiar with the basics of the C++ programming language.


Tuesday, March 18, 2014

Install Oracle JDK 8 on Raspberry Pi

This post show how to download Oracle JDK 8 on a host PC running Ubuntu Linux, copy to, install and set default java and javac on Raspberry Pi.


Visit http://www.oracle.com/technetwork/java/javase/downloads/index.html, click the download button of Java Platform (JDK) 8. Click to Accept License Agreement, download jdk-8-linux-arm-vfp-hflt.tar.gz for Linux ARM v6/v7 Hard Float ABI.

Open terminal, enter the command to copy the download file to Raspberry Pi using scp.
$ scp jdk-8-linux-arm-vfp-hflt.tar.gz pi@<Raspberry Pi>:

Log-in Raspberry Pi, enter the command to extract jdk-8-linux-arm-vfp-hflt.tar.gz to /opt directory.
$ sudo tar zxvf jdk-8-linux-arm-vfp-hflt.tar.gz -C /opt

Set default java and javac to the new installed jdk8.
$ sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0/bin/javac 1
$ sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0/bin/java 1

$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java

After all, verify with the commands with -verion option.
$ java -version
$ javac -version

BeagleBone Black vs Raspberry Pi

The video introduce the BeagleBone Black and compare it with Raspberry Pi. It go through the pros and cons of each device, show you how you can use them as well as show you footage of both the Black and the Pi working next to each other!


Rapid BeagleBoard Prototyping with MATLAB and Simulink


Rapid BeagleBoard Prototyping with MATLAB and Simulink

Leverage the power of BeagleBoard to develop and deploy practical embedded projects
Overview
  • Develop and validate your own embedded audio/video applications rapidly with Beagleboard
  • Create embedded Linux applications on a pure Windows PC
  • Full of illustrations, diagrams, and tips for rapid Beagleboard prototyping with clear, step-by-step instructions and hands-on examples
In Detail
As an open source embedded single-board computer with many standard interfaces, Beagleboard is ideal for building embedded audio/video systems to realize your practical ideas. The challenge is how to design and implement a good digital processing algorithm on Beagleboard quickly and easily without intensive low-level coding
Rapid BeagleBoard Prototyping with MATLAB and Simulink is a practical, hands-on guide providing you with a number of clear, step-by-step exercises which will help you take advantage of the power of Beagleboard and give you a good grounding in rapid prototyping techniques for your audio/video applications.
Rapid BeagleBoard Prototyping with MATLAB and Simulink looks at rapid prototyping and how to apply these techniques to your audio/video applications with Beagleboard quickly and painlessly without intensive manual low-level coding. It will take you through a number of clear, practical recipes that will help you to take advantage of both the Beagleboard hardware platform and Matlab/Simulink signal processing. We will also take a look at building S-function blocks that work as hardware drivers and interfaces for Matlab/Simulink. This gives you more freedom to explore the full range of advantages provided by Beagleboard.
By the end of this book, you will have a clear idea about Beagleboard and Matlab/Simulink rapid prototyping as well as how to develop voice recognition systems, motion detection systems with I/O access, and serial communication for your own applications such as a smart home.
What you will learn from this book
  • Understand rapid prototyping on a Windows host, including Matlab/Simulink code generation for Beagleboard
  • Set up a cross-development environment on Windows for Beagleboard
  • Access Beagleboard’s GPIO pins and RS232 communication in Matlab and Simulink
  • Develop your own S-function block in Simulink to access Beagleboard’s hardware devices
  • Create an audio player and equalizer in Simulink, including audio file reading
  • Adjust the parameters of your target system on-the-fly for the purpose of performance optimization
  • Penetrate into an infrared sensor in Matlab/Simulink for smart home applications
  • Build a video motion detection system for security applications
Approach
This book is a fast-paced guide with practical, hands-on recipes which will show you how to prototype Beagleboard-based audio/video applications using Matlab/Simlink and Sourcery Codebench on a Windows host.
Who this book is written for
Rapid BeagleBoard Prototyping with MATLAB and Simulink is great for students and academic researchers who have practical ideas and who want to build a proof-of-concept system on an embedded hardware platform quickly and efficiently. It is also useful for product design engineers who want to ratify their applications and reduce the time-to-market. It is assumed that you are familiar with Matlab/Simulink and have some basic knowledge of computer hardware. Experience in Linux is favoured but not necessary, as our software development is purely on a Windows host.



Monday, March 17, 2014

Cross compile Raspberry Pi kernel to inslude tsc2007.ko

As tsc2007 is included in the source tree of Raspberry Pi source, this post show how to download (git clone) Raspberry Pi source and cross-compile on another host PC running Ubuntu. Setup .config to include tsc2007 module with menuconfig option in make.


Please note:


Create our working directory, raspberrypi:
  • $ mkdir raspberrypi
  • cd raspberrypi
Before start our works, install the necessary tools and source code of Raspberry Pi linux:
  • $ git clone https://github.com/raspberrypi/tools.git
  • $ git clone https://github.com/raspberrypi/linux.git
  • $ cd linux
(For default setup) Prepare the .config file from pre-packaged config, bcmrpi_cutdown_defconfig:
  • $ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcmrpi_cutdown_defconfig
To generate .config with tsc2007 menu, run with menuconfig option:
  • $ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig
You can find the following code will be added in the generated .config.

CONFIG_TOUCHSCREEN_TSC2007=m



Build kernel:
  • $ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-
  • $ mkdir ../modules
  • $ make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/
  • $ cd ../tools/mkimage/
  • $ ./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image


Now insert a Raspbian installed SD Card, and run the command:
  • $ sudo rm /media/<boot-partition>/kernel.img
  • $ sudo mv kernel.img /media/<boot-partition>/
  • $ sudo rm -rf /media/<rootfs-partition>/lib/modules/
  • $ sudo rm -rf /media/<rootfs-partition>/lib/firmware/
  • $ cd ../../modules/
  • $ sudo cp -a lib/modules/ /media/<rootfs-partition>/lib/
  • $ sudo cp -a lib/firmware/ /media/<rootfs-partition>/lib/
  • $ sync



Now you can run Raspberry Pi with this new build Image. tsc2007.ko is included, but not yet run. The following steps set it run in power up. Because tsc2007 is controlled with i2c bus, so it will be enabled also.

By default, i2c is disabled in Raspbian. To run tsc2007 and i2c modules, follow the step:
  • $ sudo nano /etc/modules
    add the lines:
    i2c-bcm2708
    i2c-dev
    tsc2007

  • $ sudo nano /etc/modprobe.d/raspi-blacklist.conf
    comment the line of
    #blacklist i2c-bcm2708
  • install i2c-tools for testing
    $ sudo apt-get install i2c-tools
  • reboot
  • After reboot, run i2c-tools to test
    run the command with -1 option for rev 2 board, or -0 for rev 1 board.
    $ sudo i2cdetect -y 1
    sudo i2cdetect -y 0





You can verify tsc2007 is running by lsmod command. But I don't know any more is needed to make the touch part of "Tontec 2.4-inch TFT LCD 240x320 RGB Pixels Touch Screen Display Monitor" to work!

Sunday, March 16, 2014

Node.js + Socket.IO: share common status for all clients

Last post have individual status for each client. In this example, all client share one common status, that means client A click to change status, not only his button text will change, but also all other clients will change.


In this example:
  • All clients share a common status, commonStatus.
  • Will info new client his id, socket.id.
  • Server will broadcast all clients if any new client connected, io.sockets.emit(). Also info the number of client connected, io.sockets.clients().length.
  • Info the current common status to new connected client.
  • Info all clients if a client disconnected, socket.on('disconnect', function).
app.js
//$ npm install socket.io

var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')

//All clients have a common status
var commonStatus = 'ON';

app.listen(8080);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.sockets.on('connection', function (socket) {
    
    //Send client with his socket id
    socket.emit('your id', 
        { id: socket.id});
    
    //Info all clients a new client caaonnected
    io.sockets.emit('on connection', 
        { client: socket.id,
          clientCount: io.sockets.clients().length,
        });
        
    //Set the current common status to the new client
    socket.emit('ack button status', { status: commonStatus });
    
    socket.on('button update event', function (data) {
        console.log(data.status);
        
        //acknowledge with inverted status, 
        //to toggle button text in client
        if(data.status == 'ON'){
            console.log("ON->OFF");
            commonStatus = 'OFF';
            
        }else{
            console.log("OFF->ON");
            commonStatus = 'ON';
        }
        io.sockets.emit('ack button status', 
            { status: commonStatus,
              by: socket.id
            });
    });
    
    //Info all clients if this client disconnect
    socket.on('disconnect', function () {
        io.sockets.emit('on disconnect', 
            { client: socket.id,
              clientCount: io.sockets.clients().length-1,
            });
    });
});

index.html
<html>
<head></head>
<body>
<hi>Test Node.js with socket.io</hi>
<form action="">
<input type="button" id="buttonToggle" value="ON" style="color:blue"
       onclick="toggle(this);">
</form>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect(document.location.href);
var myId;

socket.on('on connection', function (data) {
    console.log("on connection: " + data.client);
    console.log("Number of client connected: " + data.clientCount);
});

socket.on('on disconnect',function(data) {
    console.log("on disconnect: " + data.client);
    console.log("Number of client connected: " + data.clientCount);
});

socket.on('your id',function(data) {
    console.log("your id: " + data.id);
    myId = data.id;
});

socket.on('ack button status', function (data) {
    console.log("status: " + data.status);
    
    if(myId==data.by){
        console.log("by YOU");
    }else{
        console.log("by: " + data.by);
    }
    
    if(data.status =='ON'){
        document.getElementById("buttonToggle").value="ON";
    }else{
        document.getElementById("buttonToggle").value="OFF";
    }
});

function toggle(button)
{
 if(document.getElementById("buttonToggle").value=="OFF"){
  socket.emit('button update event', { status: 'OFF' });
 }
 else if(document.getElementById("buttonToggle").value=="ON"){
  socket.emit('button update event', { status: 'ON' });
 }
}
</script>

</body>
</html>

Node.js + Socket.IO: acknowledge from server

Last example send button status to server from client, and toggle button status in client side without acknowledge from server. It is modified to send back acknowledge from server with inverted status, and update button status in client once acknowledge received.


app.js
//$ npm install socket.io

var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')

app.listen(8080);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.sockets.on('connection', function (socket) {
    socket.on('button update event', function (data) {
        console.log(data.status);
        
        //acknowledge with inverted status, 
        //to toggle button text in client
        if(data.status == 'ON'){
            console.log("ON->OFF");
            socket.emit('ack button status', { status: 'OFF' });
        }else{
            console.log("OFF->ON");
            socket.emit('ack button status', { status: 'ON' });
        }
                    
        
    });
});

index.html
<html>
<head></head>
<body>
<hi>Test Node.js with socket.io</hi>
<form action="">
<input type="button" id="buttonToggle" value="ON" style="color:blue"
       onclick="toggle(this);">
</form>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect(document.location.href);

socket.on('ack button status', function (data) {
    console.log(data.status);
    if(data.status =='ON'){
        document.getElementById("buttonToggle").value="ON";
    }else{
        document.getElementById("buttonToggle").value="OFF";
    }
});

function toggle(button)
{
 if(document.getElementById("buttonToggle").value=="OFF"){
  socket.emit('button update event', { status: 'OFF' });
 }
 else if(document.getElementById("buttonToggle").value=="ON"){
  socket.emit('button update event', { status: 'ON' });
 }
}
</script>

</body>
</html>

Next: Share common status for all clients

Node.js app using Socket.IO

Socket.IO aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. It's care-free realtime 100% in JavaScript.

This example create a simple web app to receive the status of a toggle button from client.


Before using Socket.IO on your Node.js app, run the command to install:
$ npm install socket.io

app.js run in server side:
//$ npm install socket.io

var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')

app.listen(8080);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.sockets.on('connection', function (socket) {
  socket.on('button update event', function (data) {
    console.log(data.status);
  });
});

index.html, it will be sent to and run on client side.
<html>
<head></head>
<body>
<hi>Test Node.js with socket.io</hi>
<form action="">
<input type="button" id="buttonToggle" value="ON" style="color:blue"
       onclick="toggle(this);">
</form>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect(document.location.href);

function toggle(button)
{
 if(document.getElementById("buttonToggle").value=="OFF"){
  document.getElementById("buttonToggle").value="ON";
  socket.emit('button update event', { status: 'OFF' });
 }
 else if(document.getElementById("buttonToggle").value=="ON"){
  document.getElementById("buttonToggle").value="OFF";
  socket.emit('button update event', { status: 'ON' });
 }
}
</script>

</body>
</html>

Run the app.js in server:
$ node app

Visit <server IP>:8080 with browser in client side.


Next: Acknowledge from server

Friday, March 14, 2014

Kano OS for Raspberry Pi

Kano OS is another operating system for Raspberry Pi, based on Debian Linux with a simple interface, seamless setup, automagic WiFi and Updater, and fantastic coding projects for all ages. Make and play in Minecraft, Pong, Snake, Scratch, and more.

Get the OS and Books: http://www.kano.me/downloads

Introducing Kano OS -- Beta beauty for Raspberry Pi

Install Express for Node on Raspberry Pi

Express is a web application framework for Node.js. This post show how to install Express on Raspberry Pi, locally in working directory, and generate a app.

Express for node

It's assumed you have installed Node.js on your Raspberry Pi board.

- Make a working directory, for example helloExpress.
$ mkdir helloExpress
$ cd helloExpress

- Install Express locally
$ npm install express

- Because our Express installed locally without path setting, express have to be run with path node_modules/express/bin/express. To create our Hello World, myApp. Run:
$ node_modules/express/bin/express myApp

- Then change to the created directory myApp.
$ cd myApp

- Install with npm
$ npm install

- Run the app:
$ node app

Then you can visit your express web app at port 3000 of your Pi's IP address.


Monday, March 10, 2014

Interactive map of Raspberry Pi

It is a interactive map of Raspberry Pi, RaspMap. You can check the ICs, components or connector by move your mouse pointer hover over it on the map.

http://raspmap.tsar.in/

The MagPi issue 21, March 2014

View or download issue 21 of The MagPi magazine, March 2014, HERE.

FREE Oracle Online Course: Develop Java Embedded Applications Using a Raspberry Pi

The FREE Oracle Massive Open Online Course: Develop Java Embedded Applications Using a Raspberry Pi is now open for enrollment, will start March 31st!

Java Embedded leverages your experience with Java to open the world of the Internet of Things by providing direct access to electronic sensors and mechanical devices.

This free course, designed for Java developers, is delivered over 5-weeks. Take the course at your own pace - weekly we will add new lessons, quizzes and homework assignments.

You will work on a real-world application to:

  • Read input data from switches and drive LED's using the GPIO interface
  • Read temperature and barometric pressure from an I2C device
  • Read the device's current location using a GPS UART device
  • Store and manage data collected
  • Report data to a client through a variety of communication options
  • And more!

To Enroll...

Communication between Raspberry Pi and Arduino, using Node.js

The 'serialport' module for Node.js provide basic building block to make Node.js communication with serial port. Here is a simple example to send data between Raspberry Pi and Arduino Esplora board via USB, using Node.js.

Cross-post with Arduino-er: Arduino + Raspberry Pi + Node.js



node_arduino.js, Node.js script run on Raspberry Pi side.
//To install 'serialport' locally, enter the command:
//$ npm install serialport
//Otherwise, Error: Cannot find module 'serialport' will reported

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort('/dev/ttyACM0', 
    {   baudrate: 9600,
        dataBits: 8,
        parity: 'none',
        stopBits: 1,
        flowControl: false
    });

serialPort.on("open", function () {
    console.log('open');
    serialPort.on('data', function(data) {
        console.log('data received: ' + data);
        });
    serialPort.write("Hello from Raspberry Pi\n", function(err, results) {
        console.log('err ' + err);
        console.log('results ' + results);
        });
});

The code in Arduino Esplora board.
#include <Esplora.h>
#include <TFT.h>
#include <SPI.h>
 
int prevSw1 = HIGH;
int incomingByte = 0;
String charsIn = "";
char printout[20];  //max char to print: 20
  
void setup() {
   
    EsploraTFT.begin();  
    EsploraTFT.background(0,0,0);
    EsploraTFT.stroke(255,255,255);  //preset stroke color
      
    //Setup Serial Port with baud rate of 9600
    Serial.begin(9600);
     
    //indicate start
    Esplora.writeRGB(255, 255, 255);
    delay(250);
    Esplora.writeRGB(0, 0, 0);
     
}
  
void loop() {
    int sw1 = Esplora.readButton(SWITCH_1);
    if(sw1 != prevSw1){
      if(sw1 == LOW){
        Serial.println("Hello from Arduino Esplora");
      }
      prevSw1 = sw1;
    }
     
    while (Serial.available()) {
      char charRead = Serial.read();
      charsIn.concat(charRead);
    }
    if(charsIn != ""){
      Serial.println("How are you, " + charsIn);
      charsIn.toCharArray(printout, 21);
      EsploraTFT.background(0,0,0);
      EsploraTFT.text(printout, 0, 10);
      charsIn = "";
    }
}

Thursday, March 6, 2014

PySide GUI Application Development

PySide GUI Application Development

PySide GUI Application Development

Develop more dynamic and robust GUI applications using an open source cross-platform UI framework
Overview
  • Designed for beginners to help them get started with GUI application development
  • Develop your own applications by creating customized widgets and dialogs
  • Written in a simple and elegant structure to help you easily understand how to program various GUI components
In Detail
Elegantly built GUI applications are always a massive hit among users. PySide is an open source software project that provides Python bindings for the Qt cross-platform UI framework. Combining the power of Qt and Python, PySide provides easy access to the Qt framework for Python developers and also acts as an excellent rapid application development platform available on all major operating systems.
This book aims to help you develop GUI applications easily using PySide. Python is easy to learn and use and its programs are relatively shorter than those written in other programming languages like C++ or Java. This book will introduce you to user interface programming in Python, allowing you to develop real-time applications in a shorter amount of time.
This book will take you through everything you need to know to develop UI applications. You will learn about installing/building PySide in various major operating systems as well as the basics of GUI programming. The book will then move on to discuss event management, signals and slots, and the widgets and dialogs available with PySide. Database interaction and manipulation is also covered.
In a nutshell, this book is great for learning how to program applications with GUI and for mastering how to develop your own applications and how to run them across platforms.
What you will learn from this book
  • Download and install/build PySide, a cross-platform GUI development toolkit for Python
  • Program GUI applications in an easy and efficient way
  • Create and work with windowed applications
  • Create menus, toolbars, status bars, and child windows
  • Connect your GUI to a database and manage it
Approach
An accessible and practical guide to developing GUI’s for Python applications.
Who this book is written for
This book is written for Python programmers who want to learn about GUI programming. It is also suitable for those who are new to Python but are familiar with object-oriented programming.


Tuesday, March 4, 2014

Node.js example: get command line arguments

The array process.argv will be passed containing the command line arguments. The first element will be 'node', the second element will be the name of the JavaScript file. The next elements will be any additional command line arguments.

Example:
console.log('process.argv[0]: ' + process.argv[0]);
console.log('process.argv[1]: ' + process.argv[1]);
console.log('process.argv[2]: ' + process.argv[2]);

console.log("process.argv.length: " + process.argv.length);

process.argv.forEach(function(val, index, array) {
    console.log(index + ': ' + val);
});

Node.js example: get command line arguments
Node.js example: get command line arguments

Node.js server and client, run on Raspberry Pi

Last post implement Node.js net server side, connected with client in Android device. This post show the client side implemented in Node.js.



node_client.js
var net = require('net');

var client = net.connect({port: 8081, host: '192.168.1.105'},
                function() {
                    console.log('connected');
                    client.write('world!\r\n');
                });

client.on('data', 
    function(data) {
        console.log(data.toString());
        client.end();
    }
);

client.on('end', 
    function() {
        console.log('client disconnected');
    }
);


node_server.js (same as in last post)
var os=require('os');
var net=require('net');

var networkInterfaces=os.networkInterfaces();

var port = 8081;
var count = 1;

function callback_server_connection(socket){
    var remoteAddress = socket.remoteAddress;
    var remotePort = socket.remotePort;
    socket.setNoDelay(true);
    console.log("connected: ", remoteAddress, " : ", remotePort);
    
    var msg = 'Hello ' + remoteAddress + ' : ' +  remotePort + '\r\n'
        + "You are #" + count + '\r\n';
    count++;

    socket.end(msg);
    
    socket.on('data', function (data) {
        console.log(data.toString());
    });
    
    socket.on('end', function () {
        console.log("ended: ", remoteAddress, " : ", remotePort);
    });
}

console.log("http://android-er.blogspot.com/");
console.log("http://helloraspberrypi.blogspot.com/");

console.log("node.js net server is waiting:");
for (var interface in networkInterfaces) {

    networkInterfaces[interface].forEach(function(details){
        
        if ((details.family=='IPv4') && !details.internal) {
            console.log(interface, details.address);  
        }
    });
}

console.log("port: ", port);

var netServer = net.createServer(callback_server_connection);
netServer.listen(port);


Sunday, March 2, 2014

Create TCP server using Node,js with net module, run on Raspberry Pi, connected with Android

This example create TCP server with Node.js using net module, run on Raspberry Pi. To test it with Android client side app, refer to the example at Android Server/Client example - client side using Socket.
Server side implemented with Node.js, run on Raspberry Pi.
Server side implemented with Node.js, run on Raspberry Pi.

Client side run on Android
Client side run on Android
When the Node.js program run, it list it's own IP address and assigned port, and wait for client. In client side running on Android, enter the server IP and port, and connect. When client connect to server, server side will send back a message and end the connection.


Node.js code in server side.
var os=require('os');
var net=require('net');

var networkInterfaces=os.networkInterfaces();

var port = 8081;
var count = 1;

function callback_server_connection(socket){
    var remoteAddress = socket.remoteAddress;
    var remotePort = socket.remotePort;
    socket.setNoDelay(true);
    console.log("connected: ", remoteAddress, " : ", remotePort);
    
    var msg = 'Hello ' + remoteAddress + ' : ' +  remotePort + '\r\n'
        + "You are #" + count + '\r\n';
    count++;

    socket.end(msg);
    
    socket.on('data', function (data) {
        console.log(data.toString());
    });
    
    socket.on('end', function () {
        console.log("ended: ", remoteAddress, " : ", remotePort);
    });
}

console.log("http://android-er.blogspot.com/");
console.log("http://helloraspberrypi.blogspot.com/");

console.log("node.js net server is waiting:");
for (var interface in networkInterfaces) {

    networkInterfaces[interface].forEach(function(details){
        
        if ((details.family=='IPv4') && !details.internal) {
            console.log(interface, details.address);  
        }
    });
}

console.log("port: ", port);

var netServer = net.createServer(callback_server_connection);
netServer.listen(port);


Next:
- Node.js server and client, run on Raspberry Pi


Node.js: get my IP address

This example list my IP address, coded in Node.js, with module os, run on Raspberry Pi.

list my IP address
list my IP address

var os=require('os');

var networkInterfaces=os.networkInterfaces();

for (var interface in networkInterfaces) {
    
    networkInterfaces[interface].forEach(function(details){
        
        if (details.family=='IPv4') {
            console.log(interface, details.address, 
                        " internal: ", details.internal);  
        }
    });
}