Thursday, June 17, 2021

COOJA SIMULATOR INSTALLATION IN UBUNTU

Cooja is a java-based wireless sensor network simulator distributed with Contiki.



Prior to the installation:

Check if Git, ant are installed if not use the below code for installation

for git installation:

sudo apt-get install git

for ant installation:

sudo apt-get install ant

Now setting up Cooja Simulator

Step 1: Cooja supports only if Java 8 exists because it requires java.xml.bind module. In the higher version it does not exists(removed).

Use the below code to install Java 8

sudo apt-get update
sudo apt-get install openjdk-8-jdk
Step 2:

Set environment variables for java and point them to location where java is installed.



export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=${PATH}:${JAVA_HOME}/bin

Check whether java8 is installed or not by using below command


java -version


Step 3:


Clone ContikiOS from github into any directory using command :


git clone git://github.com/contiki-os/contiki.git contiki


After cloning contiki we have to download mspsim To download this get into desired cooja folder : contiki/tools/cooja and download sub-module code for MSPSim using command :


git submodule update -- init

then

sudo apt install gcc-msp430


Step 4:

Run Cooja

From contiki/tools/cooja directory, run command


ant run

 

 

Saturday, July 11, 2020

Weather app using api in flask python

Weather App




server.py



#need to know flask as prerequisites
#importing flask
from flask import Flask, render_template, request 

# import json to load JSON data to a python dictionary 
import json 

# urllib.request to make a request to api 
import urllib.request 


app = Flask(__name__

@app.route('/'methods =['POST''GET']) 
def weather(): 
    if request.method == 'POST'
        city = request.form['city'
    else 
        city = 'bengaluru'

    # your API key will come here 
    api = 'your_api_key'


    # source contain json data from api 
    source = urllib.request.urlopen('http://api.openweathermap.org/data/2.5/weather?q='+city+'&appid='+api).read() 

    # converting JSON data to a dictionary 
    list_of_data = json.loads(source) 

    # data for variable list_of_data 
    data = { 
        "country_code"str(list_of_data['sys']['country']), 
        "cityname":str(list_of_data['name']),
        "coordinate"str(list_of_data['coord']['lon']) + ' '
                    + str(list_of_data['coord']['lat']), 
        "temp"str(list_of_data['main']['temp']) + 'k'
        "pressure"str(list_of_data['main']['pressure']), 
        "humidity"str(list_of_data['main']['humidity']), 
    } 
    print(data) 
    return render_template('main.html'data = data) 



if __name__ == '__main__'
    app.run(debug = True

main.html


<html>
<head>
  <title>weather</title>
</head>

<body>
    <h1><center>weather</center></h1>
  <br />
  <br />
  <center class="row">
    <form method="post" class="col-md-6 col-md-offset-3">
      <div class="input-group">
        <input type="text" class="form-control" name="city" placeholder="Search" default="bengaluru">
        <div class="input-group-btn">
          <button class="btn btn-primary" type="submit">
            <i class="glyphicon glyphicon-search"></i>
          </button>
        </div>
        <form>
  </center>
  <div class="row">
    {% if data.country_code and data.coordinate and data.temp and data.pressure and data.humidity %}
    <div class="col-md-6 col-md-offset-3">
      <h3>country code : {{data.country_code}}</h1>
        <h5>City name : {{data.cityname}}</h5>
        <h5>coordinate : {{data.coordinate}}</h5>
        <h5>temp (in kelvin) : {{data.temp}}</h5>
        <h5>pressure : {{data.pressure}} </h5>
        <h5>humidity : {{data.humidity}}</h5>
    </div>
    {% endif %}
  </div>
</body>
</html>


Follow my github account : Sharath Hebbar

follow my blog : Delta

Saturday, May 2, 2020

Getting started with Flask

Getting started with Flask

Web Application Framework or simply Web Framework represents a collection of libraries and modules that enables a web application developer to write applications

Flask is a web application framework written in Python. It is developed by Armin Ronacher.


 Flask is based on the Werkzeug WSGI toolkit and Jinja2 template engine.

Installing Flask in python

pip install flask

First project in flask

from flask import Flask
#it is double underscore
app = Flask(__name__)
@app.route('/')
 def hello_world():
          return 'Hello World’
#it is double underscore
if __name__ == '__main__':
           app.run()


The image is from Google

PS: you need to know python
Support:

Wednesday, April 29, 2020

Login page


Login page
//main.html
<html> 
<head> <link rel="stylesheet" href="style.css"></head> 
<body> <form> <div class = "profile"> <center> <img src = "s.png" alt = "S" class = "S"> <br/> <b><h1>S </h1></b> <br/></center></div><div class="details"> <center>
 <input type ="text" placeholder="Enter E-mail id" name ="E-mail"> <br/> <input type ="password" placeholder="Enter password" name ="pass"> <br/> <button type="button">Login</button> <br/> <label> <input type="checkbox" checked="checked" name="remember"> Remember me </label> <br/></center></div> <br/><center> <div><a href="">Forget Password!</a></div> <br> <div class="acc"> <label>Don't have an account <a href="">Click Here!</a></label></div> </center> 
</form> </body>
 </html>

//style.css

body { width: 100%; height:100%; font-family: 'Open Sans', sans-serif; } input[type=text], input[type=password] { width: 30%; padding: 12px 20px; margin: 8px 0; display: inline-block; border: 2px solid #ccc; box-sizing: border-box;} button { background-color: #FF1493; color: white; padding: 14px 20px; margin: 8px 0; border: none; cursor: pointer; width: 10%;} button:hover { opacity: 0.8;} img.collision { width: 20%; border-radius: 45%; background-color: #483D8B;} div.acc{ text-align: center;} h1{font-family: sans-serif; }h4{font-family: sans-serif;}div.acc{ color: }

For more details :

Saturday, March 7, 2020

Forest fire alerting system using Arduino Gsm module


#include "dht.h"
#include <SoftwareSerial.h>

#include <TinyGPS.h>
float lat = 28.5458,lon = 77.1703; // create variable for latitude and longitude object 

#define sen1 A0
#define sen2 A1
#define sen3 A2
#define sen4 A3

#define buzz 7

dht DHT1;
dht DHT2;
dht DHT3;
dht DHT4;

String latitude = String(lat,6);
String longitude = String(lon,6);

SoftwareSerial gpsmodule(3,4);//connection tx rx

SoftwareSerial BTmodule(8,9); //connection tx rx

SoftwareSerial GSMmodule(10 ,11); //connection tx rx

TinyGPS gps; // create gps object

void initModule(String cmd, char *res, int t)
{
  while(1)
  {
    Serial.println(cmd);
    GSMmodule.println(cmd);
    delay(100);
    while(GSMmodule.available()>0)
    {
       if(GSMmodule.find(res))
       {
        Serial.println(res);
        delay(t);
        return;
       }

       else
       {
        Serial.println("Error");
       }
    }
    delay(t);
  }
}



void setup() {
 
 
  Serial.begin(9600);
  gpsmodule.begin(9600);
  BTmodule.begin(9600);
  GSMmodule.begin(9600);
  pinMode(buzz, OUTPUT);
  delay(500);
}

void loop() {

  while(gpsmodule.available()){ // check for gps data
    if(gps.encode(gpsmodule.read()))// encode gps data
    {
    gps.f_get_position(&lat,&lon);
    }
    }

 
  Serial.println(latitude+";"+longitude);
 
  DHT1.read11(sen1);
 
  Serial.print("Temperature in Celsius");
  Serial.print(DHT1.temperature);
  Serial.print("    Current humidity = ");
  Serial.print(DHT1.humidity);
  Serial.println();
 
  DHT2.read11(sen2);
 
  Serial.print("Temperature in Celsius");
  Serial.print(DHT2.temperature);
  Serial.print("    Current humidity = ");
  Serial.print(DHT2.humidity);
  Serial.println();
 
  DHT3.read11(sen3);
 
  Serial.print("Temperature in Celsius");
  Serial.print(DHT3.temperature);
  Serial.print("    Current humidity = ");
  Serial.print(DHT3.humidity);
  Serial.println();

  DHT4.read11(sen4);
 
  Serial.print("Temperature in Celsius");
  Serial.print(DHT4.temperature);
  Serial.print("    Current humidity = ");
  Serial.print(DHT4.humidity);
  Serial.println();

  delay(1000);
 
  GSMmodule.println("AT");
   delay(500);
  GSMmodule.println("AT+CMGF=1");
   delay(500);

   GSMmodule.print("AT+CMGS=\"+XXxxxxxxxxxx\"\r");
 
   GSMmodule.println('"');
   delay(1000);
    Serial.println();
    digitalWrite(buzz, LOW);
    if(DHT1.temperature > 70.0 || DHT1.humidity < 20.0 )
    {
     
        digitalWrite(buzz, HIGH);
        BTmodule.print("Temperature in Celsius");
        BTmodule.print(DHT1.temperature);
        BTmodule.print("    Current humidity = ");
        BTmodule.print(DHT1.humidity);
        BTmodule.println();

        Maps();
     
        Fire();
        BTmodule.println("Might be Fire in the grid One");
        GSMmodule.println("Might be Fire in the grid One");
        Serial.println("Might be Fire in the grid One");

        callMe();
    }
    Serial.println();
    if(DHT2.temperature > 70.0 || DHT2.humidity < 20.0 )
    {
        digitalWrite(buzz, HIGH);
       
        BTmodule.print("Temperature in Celsius");
        BTmodule.print(DHT2.temperature);
        BTmodule.print("    Current humidity = ");
        BTmodule.print(DHT2.humidity);
        BTmodule.println();

        Maps();
       
        Fire();
        BTmodule.println("Might be Fire in the grid two");
        GSMmodule.println("Might be Fire in the grid two");
        Serial.println("Might be Fire in the grid two");
       
        callMe();
    }
    Serial.println();
    if(DHT3.temperature > 70.0 || DHT3.humidity < 20.0 )
    {
        digitalWrite(buzz, HIGH);
        BTmodule.print("Temperature in Celsius");
        BTmodule.print(DHT3.temperature);
        BTmodule.print("    Current humidity = ");
        BTmodule.print(DHT3.humidity);
        BTmodule.println();
       
        Maps();
       
        Fire();
       
        BTmodule.println("Might be Fire in the grid three");
        GSMmodule.println("Might be Fire in the grid three");
        Serial.println("Might be Fire in the grid three");
       
        callMe();
    }
    Serial.println();
    if(DHT4.temperature > 70.0 || DHT4.humidity < 20.0 )
    {
        digitalWrite(buzz, HIGH);
        BTmodule.print("Temperature in Celsius");
        BTmodule.print(DHT4.temperature);
        BTmodule.print("    Current humidity = ");
        BTmodule.print(DHT4.humidity);
        BTmodule.println();

       
        Maps();
       
        Fire();
        BTmodule.println("Might be Fire in the grid four");
        GSMmodule.println("Might be Fire in the grid four");
        Serial.println("Might be Fire in the grid four");
       
        callMe();
        }
        Serial.println();
       digitalWrite(buzz, LOW);
}


void callMe()
{
        Serial.println("Calling  ");
        GSMmodule.println("ATD+XXxxxxxxxxxx;");// number and semicolon is compulsory at the end of number
        delay(1000);
        Serial.println("Call ended");
}

void Fire()
{
       
        Serial.println("FIRE ALERT !!!!!");
        BTmodule.println("FIRE ALERT !!!!!");
        GSMmodule.println("FIRE ALERT !!!!!");
}

void Maps()
{
        BTmodule.println(latitude+";"+longitude);
        GSMmodule.println(latitude+";"+longitude);
        Serial.println(latitude+";"+longitude);

        Serial.print("http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=");
        GSMmodule.print("http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=");
        BTmodule.print("http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=");
       
}


For more details :


Support :

Image steganography using python

from PIL import Image
def genData(data):
# list of binary codes
# of given data
newd = []
for i in data:
newd.append(format(ord(i), '08b'))
return newd
# Pixels are modified according to the
# 8-bit binary data and finally returned
def modPix(pix, data):
datalist = genData(data)
lendata = len(datalist)
imdata = iter(pix)
for i in range(lendata):
# Extracting 3 pixels at a time
pix = [value for value in imdata.next()[:3] +
imdata.next()[:3] +
imdata.next()[:3]]
# Pixel value should be made
# odd for 1 and even for 0
for j in range(0, 8):
if (datalist[i][j]=='0') and (pix[j]% 2 != 0):
if (pix[j]% 2 != 0):
pix[j] -= 1
elif (datalist[i][j] == '1') and (pix[j] % 2 == 0):
pix[j] -= 1
# Eigh^th pixel of every set tells
# whether to stop ot read further.
# 0 means keep reading; 1 means the
# message is over.
if (i == lendata - 1):
if (pix[-1] % 2 == 0):
pix[-1] -= 1
else:
if (pix[-1] % 2 != 0):
pix[-1] -= 1
pix = tuple(pix)
yield pix[0:3]
yield pix[3:6]
yield pix[6:9]
def encode_enc(newimg, data):
w = newimg.size[0]
(x, y) = (0, 0)
for pixel in modPix(newimg.getdata(), data):
# Putting modified pixels in the new image
newimg.putpixel((x, y), pixel)
if (x == w - 1):
x = 0
y += 1
else:
x += 1
# Encode data into image
def encode():
print "Encode"
img = raw_input("Enter image name(with extension): ")
image = Image.open(img, 'r')
image.show()
data = raw_input("Enter data to be encoded : ")
if (len(data) == 0):
raise ValueError('Data is empty')
newimg = image.copy()
encode_enc(newimg, data)
new_img_name = raw_input("Enter the name of new image(with extension): ")
newimg.save(new_img_name, str(new_img_name.split(".")[1].lower()))
# Decode the data in the image
def decode():
print "Decode"
img = raw_input("Enter image name(with extension) :")
image = Image.open(img, 'r')
image.show()
data = ''
imgdata = iter(image.getdata())
while (True):
pixels = [value for value in imgdata.next()[:3] +
imgdata.next()[:3] +
imgdata.next()[:3]]
# string of binary data
binstr = ''
for i in pixels[:8]:
if (i % 2 == 0):
binstr += '0'
else:
binstr += '1'
data += chr(int(binstr, 2))
if (pixels[-1] % 2 != 0):
return data
# Main Function
def main():
#declaring key
pkey = 123
a = int(raw_input(":: Image Steganography ::\n"
"1.Encrypt\n2.Decrypt\n"))
if (a == 1):
print("Encryption")
encode()
print("Data has sucessfully Encrpyted")
elif (a == 2):
print("Decryption")
Pkey = int(raw_input("Enter the key to be decrypted : "))
if(pkey == Pkey):
print("--Decoded word-- " + decode())
else :
raise Exception("Enter correct key")
else:
raise Exception("Enter correct input")
# Driver Code
if __name__ == '__main__' :
# Calling main function
main()

Support:
Delta
For more info :
https://github.com/SharathHebbar/Image-steganography/blob/master/image.py