Algotithm to Convert 4 byte Hex to 32 bit float

 I really struggled hard to find out some sorts of algorithm to convert 4 hex bytes to 32 bit float for my requirement on some analysis of MODBUS protocol. I didn’t find it and it tok me nearly 2 days to design this. Here is the algorithm.. float ModbusRead(byte id,byte msbAddress,byte lsbAddress,byte msbCrc,byte lsbCrc){ num=1.00; Serial.write(id); Serial.write(0x03); Serial.write((byte)msbAddress); Serial.write((byte)lsbAddress); Serial.write((byte)0x00); Serial.write(0x02); Serial.write(msbCrc); Serial.write(lsbCrc); delay(1000); for(i=0;i<9;i++) { if(!Serial.available()) { for (int x=0;x < 9;x++) { reply[x]=0x00; } while(Serial.available()){} break; } reply[i]=Serial.read(); } while(Serial.available()){} if((reply[3] & 0x80)!=0) num=num*-1; reply[3]=reply[3]<<1; if((reply[4] & 0x80)!=0x00)…

Read More

Room temperatuer logger using arduino and JAVA

 This post is all about a temperature logger module using two sensors(LM35) and uses serial communication to log data to MySQL server. And it does so by using Arduino at the logger end and JAVA at the server.   The concept is so simple that the Arduino uses LM35 (providing analog output for measured temperature) ,which is connected to one of the analogIn pin of Arduino. The sketch burned to Arduino converts the read value from the pin to corresponding temperature. And it sends the data through the serial port.…

Read More

Control VLC Player using Android (Wifi Connected)

    My first application of Android comes here.In my first tutorial on Controlling VLC using JAVA you can see that the VLC provides a Web interface from which it can be controlled and it also accepts certain commands.So that can be used to control the media player in Local Area Network using any programming language.This time its Android Code: MainActivity.Java package com.example.first_app;import java.net.Authenticator;import java.net.URL;import android.os.Build;import android.os.Bundle;import android.os.StrictMode;import android.annotation.SuppressLint;import android.annotation.TargetApi;import android.app.Activity;import android.content.Intent;import android.graphics.Color;import android.view.Menu;import android.view.View;import android.widget.Button;import android.widget.SeekBar;import android.widget.SeekBar.OnSeekBarChangeListener;import android.widget.TextView;public class MainActivity extends Activity { @TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressLint(“NewApi”) @Override protected void onCreate(Bundle…

Read More

Sending Message from PC through mobile using AT Commands over Bluetooth

AT Commands:              AT or attention are set of commands those are used to communicate with GSM modems.I am not going much about it as you can google it.I tried using the AT commands through Bluetooth  which was successful and finally integrated it to JAVA so that I can send message through my mobile using an interface instead of hyper-terminal.Before getting it started check your mobile if it supports the commands or not by using Hyper-terminal or any serial port Software.                In the below codes i have used RxTx serial…

Read More

Getting Facebook Access Token for JAVA applications

    When for the first time i used facebook API in my java application using the  library restFb i faced real trouble with the access token .For that i browsed a lot to get the token at last i was able.So to make it easy here are the steps to get the access token that is valid for 2 months. Step:1   First of all create a facebook application and goto the application page.goto tools and click on APIExplorer   in the menu as shown below select your application…  click on get…

Read More

Storing configuration data for JAVA applications

programming

    Many times it is required to store some configuration settings for your application so that it can use again and again from where it left. Or the application can start with some specific parameters. The properties file can come in handy in such requirements. First, let’s write something to the properties file.   Code: import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Properties; public class App {   public static void main(String[] args) {     Properties prop = new Properties();     OutputStream output = null;     try {        …

Read More

Controlling VLC media player using JAVA

programming

Basically, I was looking for a method to communicate with the VLC media player so that I can get the currently playing video on the player and my app can search the internet and get the details about the movie. For that, I googled a lot and finally came to know that VLC has a web interface and I used that with my JAVA app to control and getting details of the movie.     Setting Up First, open the VLC and go to tools->preferences and check the All radio…

Read More

Sending Email using JAVA mail API and gmail account

                Sending a mail using JAVA mail API in JAVA is really a easy part.Here i am posting the codes to simply send a mail using the API.First you have to download the JAVA mail library and add it to your build path. Code: package com.oksbwn.mail;import java.awt.Color;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.io.FileInputStream;import java.io.InputStream;import java.util.Properties;import javax.mail.*;import javax.mail.internet.*;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JTextField;import javax.swing.JTextPane;import com.oksbwn.ErrorHandling.handleExceptions;import com.oksbwn.popUp.popMe;//import com.oksbwn.popUp.popMe;public class SendMail  extends JFrame {    final static JFrame frame = new JFrame();    private static final long serialVersionUID = 1L;    public void SendMailTo(){       //public static…

Read More

A Tweet Gallery in JAVA

                         As the title says the above image is the screenshot of a tweet gallery that i have designed using JAVA and JAVAFX., to access the tweets i have used twitter4j library.Below are the codes to design the gallery.Also My-SQL database is used to store the tweets periodically and when clicked on view then it shows the latest 25 tweets from the database. Code to authenticate User: package com.oksbwn.Y2014.twitter;import twitter4j.Twitter;import twitter4j.TwitterFactory;import twitter4j.conf.ConfigurationBuilder;public class getAuthorized { public Twitter auth() { String consumerKey = “”; String consumerSecret =””; String accessToken =…

Read More

MySQL database access using Python in Raspberry Pi

          While working with Python in Raspberry Pi it might be useful to have a database access for your application or somewher it is required.Or may be as a beginner you would like to use MySQL with Python.Here i have compiled a post on how to use MySQL with Python…               First of all you have to install python-MySQLdb which interacts between the My-SQL database and the Python.So to install it in the Raspberry-Pi terminal type..           sudo apt-get install python-mysqldb I have already installed so my…

Read More