Thursday, October 15, 2015

Good Movies to Motivate Self and Study


1.Race the Sun
2.Spare parts
4.Paper Planes
5.October Sky
6.Antitrust
7.pURSUIT OF hAPPYNESS
8.tHE SECRET - DOCUMETARRY
9.Dead Poets Society
10.Imitation game
11. Fastest Indian

Monday, July 6, 2015

Assigning SSID/Password remotely - Smartconfig on ESP8266

 

I used latest SDK 1.1.0 ( both Opensdk or Espressif sdk is fine) , and run the smart config code below , But the Official espressif IOT esptouch apk was not able to assign the SSID or Password

Then used this esp8266 dash app from

https://github.com/DeqingSun/ESP8266-Dash-Button/tree/master/pre_compiled_bin_files

app_SDK_110.apk

IN case if it didn’t work try to replace following files from

esp_iot_sdk_v1.1.0_15_05_26\lib

-libsmartconfig.a

-libmain.a

To your development environment

clip_image002

Smartconfig Code on ESP8266

#include "ets_sys.h"

#include "osapi.h"

#include "user_interface.h"

#include "smartconfig.h"

sc_type SC_Type = 0;

void ICACHE_FLASH_ATTR

smartconfig_done(sc_status status, void *pdata)

{

int i =0;

switch(status) {

case SC_STATUS_WAIT:

os_printf("SC_STATUS_WAIT\n");

break;

case SC_STATUS_FIND_CHANNEL:

os_printf("SC_STATUS_FIND_CHANNEL\n");

break;

case SC_STATUS_GETTING_SSID_PSWD:

os_printf("SC_STATUS_GETTING_SSID_PSWD\n");

break;

case SC_STATUS_LINK:

os_printf("SC_STATUS_LINK\n");

struct station_config *sta_conf = pdata;

wifi_station_set_config(sta_conf);

wifi_station_disconnect();

wifi_station_connect();

break;

case SC_STATUS_LINK_OVER:

os_printf("SC_STATUS_LINK_OVER\n");

if (SC_Type == SC_TYPE_ESPTOUCH) {

uint8 phone_ip[4] = {0};

os_memcpy(phone_ip, (uint8*)pdata, 4);

os_printf("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]);

}

smartconfig_stop();

break;

}

}

user_rf_pre_init()

{

}

void user_init(void)

{

uart_init(115200, 115200);

os_printf("SDK version:%s\n", system_get_sdk_version());

SC_Type = SC_TYPE_ESPTOUCH;

wifi_set_opmode(STATION_MODE);

smartconfig_start(SC_Type, smartconfig_done);

}

Sample run of the code on esp8266

SDK version:1.1.0

TYPE: ESPTOUCH V2.1

mode : sta(18:fe:34:a1:c3:5f)

add if0

scandone

scandone

scandone

SC_STATUS_FIND_CHANNEL

T|!!!

T|!!!

T|!!!

T|sniffer on ch:6

T|PHONE MAC: 34 bb 26 92 f0 d7

T|AP MAC : 2c 3f 38 7e 62 12

T|Head Len : 66

SC_STATUS_GETTING_SSID_PSWD

T|SYNC STATUS

T|103-5

T|0-6

T|17-7

T|16-0

T|154-2

T|133-3

T|103-5

T|0-6

T|17-7

T|16-0

T|0-1

T|SSID: internet

T|all lenth: 16,pswd lenth: 0

T|SCAN CRC SSID: 1

T|133-3

T|10-4

T|0-16-2

T|1-0-1

T|2-154-1

T|3-133-2

T|4-10-1

T|5-103-2

T|6-0-2

T|7-17-2

T|pswd:

T|ssid: internet

T|token: 10

SC_STATUS_LINK

scandone

reconnect

Monday, June 8, 2015

Publishing MQTT every 30 Sec and Sleep ( NodeMCU v2)

image
Connect GPIO16 ( D0) and RST Pin for MCu to wakeup from deep sleep after specified Time.

 

image 

 

After the Mqtt is sent , Put sleep in mqttPublishedCb ( callback ) .

system_deep_sleep(30000000) puts mcu to sleep for 30s.

If you want that system should not wakeup (no wakeup until rst pin to low )

system_deep_sleep(0)

=================================

load ...
WIFI_INIT
MQTT_InitConnection
MQTT_InitClient
mode : sta(18:fe:34:a1:c3:5f)
add if0
STATION_IDLE
scandone
STATION_IDLE
add 0
aid 6
pm open phy_2,type:2 0 0
cnt

connected with SSID, channel 6
dhcp client start...
STATION_IDLE
ip:192.168.43.35,mask:255.255.255.0,gw:192.168.43.1

MQTT Connecting.....

MQTT Connecting 2.....
TCP: Connect to ip  192.168.43.206:1883
espconn_connect = 0
MQTT: Connected to broker 192.168.43.206:1883
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: data received 4 bytes
MQTT: Connected to 192.168.43.206:1883
MQTT: Connected
MQTT: queuing publish, length: 23, queue size(0/2048)
MQTT: Sending, type: 3, id: 0000
TCP: Sent
MQTT: Published
rm match
pm close 7 0 0/1324668
del if0
usl
sul 0 0
TCP: Reconnect to 192.168.43.206:1883
deep sleep 30s

=========================

Deep Sleep Option

  1. deep_sleep_set_option(0): Radio calibration after deep-sleep wake up depends
    on init data byte 108.
  2. deep_sleep_set_option(1): Radio calibration is done after deep-sleep wake
    up; this increases the current consumption.
  3. deep_sleep_set_option(2): No radio calibration after deep-sleep wake up;
    this reduces the current consumption.
  4. deep_sleep_set_option(4): Disable RF after deep-sleep wake up, just like
    modem sleep; this has the least current consumption; the device is not able
    to transmit or receive data after wake up.

I tried No RF calibration but it dosent work. Probably some bit has to be set in esp_data bin file….need to explore.

Testing MQTT Broker on Windows

1.Start Mosquito Broker

image

with –v option  ( Verbose)

it start listening by default on 1883 Port.

image

 

open Mqtt.fx ( mqtt client) –>Select Local mosquito .

image

Subscribe

image

 

Publish

image

Flashing NodeMCU V2 ( ESP8266) 32Mbit with Open SDK Firmware

Due to Memory/Flash Size Layout change flashing the firmware on esp8266 with esptool.py doesn't works

Most of will see following ( Baud 74880)  and user code will not boot.

clip_image001

 

The solution to problem is simple just use the flash tool from bbs of expressif ( official site)  with following settings and it will work.

SPI Speed – 40mhz

SPI mode – DIO

Flash Size – 32Mb

0x00000.bin and 0x40000.bin at same 0x00000 and 0x40000 location.

image

Wednesday, June 3, 2015

Light Control ESP8266 AJAX

Button Version 1
( Here Ajax is sending Get reqest with ON/OFF u could add button id also for particular gpio, Lua webserver parses this and turns the GPIO on/off)

<html>
<head>
<script language="javascript">
function colorchange(id)
{
var xmlhttp;
xmlhttp=new XMLHttpRequest();
if(document.getElementById(id).value == 'OFF' )
{
document.getElementById(id).style.background = '#ff0000';
document.getElementById(id).value = 'ON';
xmlhttp.open("GET","button.htm?ON",true);
xmlhttp.send();
}
else
{
document.getElementById(id).style.background = '#00ff00';
document.getElementById(id).value = 'OFF';
xmlhttp.open("GET","button.htm?OFF",true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<input type="button" id="btn" onclick="colorchange('btn');" value ="OFF" style="background:#00ff00;"/>
</body>
</html>


























It Toggles color on pressing it.
clip_image001
Button Version 2
(Pure CSS Graphics copy css code in html for easier buf copy.)
Button.html
<html>
<head>
<title> New Document </title>
<meta name="Author" content="Alok Prasad">
<script language="javascript">
function colorchange(id)
{
var xmlhttp;
xmlhttp=new XMLHttpRequest();
if(document.getElementById(id).name == 'OFF' )
{
document.getElementById(id).name = 'ON';
xmlhttp.open("GET","a.htm?ON",true);
xmlhttp.send();
}
else
{
document.getElementById(id).name= 'OFF';
xmlhttp.open("GET","a.htm?OFF",true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<link rel="stylesheet" href="button2.css">
<input type="checkbox" id="switch" name="OFF" onclick="colorchange('switch');">
<label for="switch" class="switch"></label>
</body>
</html>




























Button2.css
*, *:after, *:before {
box-sizing: border-box;
}
#switch {
visibility:hidden;
clip:rect(0 0 0 0);
position: absolute;
left: 9999px;
}
.switch {
display: block;
width: 130px;
height: 60px;
margin: 70px auto;
position: relative;
background: #ced8da; /* Old browsers */
background: -moz-linear-gradient(left, #ced8da 0%, #d8e0e3 29%, #ccd4d7 34%, #d4dcdf 62%, #fff9f4 68%, #e1e9ec 74%, #b7bfc2 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#ced8da), color-stop(29%,#d8e0e3), color-stop(34%,#ccd4d7), color-stop(62%,#d4dcdf), color-stop(68%,#fff9f4), color-stop(74%,#e1e9ec), color-stop(100%,#b7bfc2)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #ced8da 0%,#d8e0e3 29%,#ccd4d7 34%,#d4dcdf 62%,#fff9f4 68%,#e1e9ec 74%,#b7bfc2 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #ced8da 0%,#d8e0e3 29%,#ccd4d7 34%,#d4dcdf 62%,#fff9f4 68%,#e1e9ec 74%,#b7bfc2 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, #ced8da 0%,#d8e0e3 29%,#ccd4d7 34%,#d4dcdf 62%,#fff9f4 68%,#e1e9ec 74%,#b7bfc2 100%); /* IE10+ */
background: linear-gradient(to right, #ced8da 0%,#d8e0e3 29%,#ccd4d7 34%,#d4dcdf 62%,#fff9f4 68%,#e1e9ec 74%,#b7bfc2 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ced8da', endColorstr='#b7bfc2',GradientType=1 ); /* IE6-9 */
transition: all 0.2s ease-out;
cursor: pointer;
border-radius: 0.35em;
box-shadow:
0 0 1px 2px rgba(0,0,0,0.7),
inset 0 2px 0 rgba(255,255,255,0.6),
inset 0 -1px 0 1px rgba(0,0,0,0.3),
0 8px 10px rgba(0,0,0,0.15);
}
.switch:before {
display:block;
position: absolute;
left: -35px; right: -35px;
top: -25px; bottom: -25px;
z-index: -2;
content: "";
border-radius: 0.4em;
background: #d5dde0;
background: linear-gradient(#d7dfe2, #bcc7cd);
box-shadow:
inset 0 2px 0 rgba(255,255,255,0.6),
inset 0 -1px 1px 1px rgba(0,0,0,0.3),
0 0 8px 2px rgba(0,0,0,0.2),
0 2px 4px 2px rgba(0,0,0,0.1);
pointer-events: none;
transition: all 0.2s ease-out;
}
.switch:after {
content: "";
position: absolute;
right: -25px;
top: 50%;
width: 16px;
height: 16px;
border-radius: 50%;
background: #788b91;
margin-top: -8px;
z-index: -1;
box-shadow:
inset 0 -1px 8px rgba(0,0,0,0.7),
inset 0 -2px 2px rgba(0,0,0,0.2),
0 1px 0 white,
0 -1px 0 rgba(0,0,0,0.7),
-47px 32px 15px 13px rgba(0,0,0,0.25);
}
#switch:checked ~ .switch {
background: #b7bfc2; /* Old browsers */
background: -moz-linear-gradient(left, #b7bfc2 0%, #e1e9ec 26%, #fff9f4 32%, #d4dcdf 38%, #ccd4d7 66%, #d8e0e3 71%, #ced8da 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#b7bfc2), color-stop(26%,#e1e9ec), color-stop(32%,#fff9f4), color-stop(38%,#d4dcdf), color-stop(66%,#ccd4d7), color-stop(71%,#d8e0e3), color-stop(100%,#ced8da)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #b7bfc2 0%,#e1e9ec 26%,#fff9f4 32%,#d4dcdf 38%,#ccd4d7 66%,#d8e0e3 71%,#ced8da 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #b7bfc2 0%,#e1e9ec 26%,#fff9f4 32%,#d4dcdf 38%,#ccd4d7 66%,#d8e0e3 71%,#ced8da 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, #b7bfc2 0%,#e1e9ec 26%,#fff9f4 32%,#d4dcdf 38%,#ccd4d7 66%,#d8e0e3 71%,#ced8da 100%); /* IE10+ */
background: linear-gradient(to right, #b7bfc2 0%,#e1e9ec 26%,#fff9f4 32%,#d4dcdf 38%,#ccd4d7 66%,#d8e0e3 71%,#ced8da 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b7bfc2', endColorstr='#ced8da',GradientType=1 ); /* IE6-9 */
}
#switch:checked ~ .switch:after {
background: #b1ffff;
box-shadow:
inset 0 -1px 8px rgba(0,0,0,0.7),
inset 0 -2px 2px rgba(0,0,0,0.2),
0 1px 0 white,
0 -1px 0 rgba(0,0,0,0.5),
-110px 32px 15px 13px rgba(0,0,0,0.25);
}





















































































Screenshot
clip_image002
Lua Web Server ( Based on Button 1)
wifi.setmode(wifi.SOFTAP)
print(wifi.sta.getip())
led1 = 3
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
buf = buf.."<head> <script language=\"javascript\">";
buf = buf.."function colorchange(id) { var xmlhttp; xmlhttp=new XMLHttpRequest();";
buf = buf.."if(document.getElementById(id).value == \'OFF\' )";
buf = buf.."{ document.getElementById(id).style.background = \'#ff0000\'; ";
buf = buf.."document.getElementById(id).value = \'ON\';";
buf = buf.."xmlhttp.open(\"GET\",\"a.htm?pin=ON2\",true);xmlhttp.send();}";
buf = buf.."else { document.getElementById(id).style.background = \'#00ff00\'; ";
buf = buf.."document.getElementById(id).value = \'OFF\'; xmlhttp.open(\"GET\",\"a.htm?pin=OFF2\",true);xmlhttp.send();}}";
buf = buf.." </script></head> <body>";
buf = buf.."<input type=\"button\" id=\"btn\" onclick=\"colorchange(\'btn\');\" value =\"OFF\" style=\"background:#00ff00;\"></body></html>";
local _on,_off = "",""
if(_GET.pin == "ON1")then
gpio.write(led1, gpio.HIGH);
elseif(_GET.pin == "OFF1")then
gpio.write(led1, gpio.LOW);
elseif(_GET.pin == "ON2")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "OFF2")then
gpio.write(led2, gpio.LOW);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)













































See the youtube Video for demonstration
https://www.youtube.com/watch?v=CeKbD82FhKY











Sunday, April 12, 2015

Tabbed Terminal in Ubuntu

If you want to do it from the command then install xdotools.

sudo apt-get install xdotool

then type in the terminal as

xdotool key ctrl+shift+t

That will open the new tab in the terminal.

Note: type xdotool command as it is.

As additional information: To open a new tab in the current opened terminal you can press SHIFT+CTRL+T.

Changing Interface name using Udev for vmxnet3 driver type( Ubuntu)

I wanted to change the name of interface whose driver is vmxnet3 by appending X and ending with

Interface count

Use udevadm to list properties and attributes

 

root@cisco-pkt-vm:~# udevadm info -a -p /sys/class/net/eth2

looking at device '/devices/pci0000:00/0000:00:15.0/0000:03:00.0/net/Xeth2':

KERNEL=="eth2"

SUBSYSTEM=="net"

DRIVER==""

ATTR{mtu}=="1500"

ATTR{type}=="1"

ATTR{netdev_group}=="0"

ATTR{flags}=="0x1003"

ATTR{speed}=="10000"

ATTR{dormant}=="0"

ATTR{addr_assign_type}=="3"

ATTR{dev_id}=="0x0"

ATTR{duplex}=="full"

ATTR{iflink}=="2"

ATTR{addr_len}=="6"

ATTR{address}=="00:0c:29:ce:b0:11"

ATTR{operstate}=="up"

ATTR{broadcast}=="ff:ff:ff:ff:ff:ff"

ATTR{tx_queue_len}=="1000"

ATTR{ifalias}==""

ATTR{ifindex}=="2"

ATTR{link_mode}=="0"

looking at parent device '/devices/pci0000:00/0000:00:15.0/0000:03:00.0':

KERNELS=="0000:03:00.0"

SUBSYSTEMS=="pci"

DRIVERS=="vmxnet3"

ATTRS{irq}=="18"

 

 

Once we know the properties adding rules in udev.

Edit file /etc/udev/rules.d/70-persistent-net.rules

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="vmxnet3", KERNEL=="eth*", NAME="Xeth$attr{ifindex}"

 

After reboot you wil see it being eth2 being renamed to Xeth2

 

root@cisco-pkt-vm:~# ifconfig

 

Xeth2 Link encap:Ethernet HWaddr 00:0c:29:ce:b0:11

inet6 addr: fe80::20c:29ff:fece:b011/64 Scope:Link

Xeth3 Link encap:Ethernet HWaddr 00:0c:29:ce:b0:1b

collisions:0 txqueuelen:1000

RX bytes:120 (120.0 B) TX bytes:3745 (3.7 KB)

 

Xeth4 Link encap:Ethernet HWaddr 00:0c:29:ce:b0:25

inet6 addr: fe80::20c:29ff:fece:b025/64 Scope:Link

RX bytes:120 (120.0 B) TX bytes:3745 (3.7 KB)

Xeth5 Link encap:Ethernet HWaddr 00:0c:29:ce:b0:2f

inet6 addr: fe80::20c:29ff:fece:b02f/64 Scope:Link

RX bytes:120 (120.0 B) TX bytes:3745 (3.7 KB)

Installing Intel X520 CNA Card on ESX

 

1.download driver
https://my.vmware.com/group/vmware/details?downloadGroup=DT-ESXI55-INTEL-IXGBE-3214&productId=353

2.put in ESX 5.5 machine using SCP

3.run offline installiner

4.esxcli software vib install -d /[absolute_path]/ixgbe-3.21.4-offline_bundle-1710123.zip

Recovery and Restore Partition ( Freeware Alternative to Norton Ghost)

Save and Restore using partimage

partimage -b -z1 -o -d save /dev/sdb2 /recovery/trixorg.gz

partimage -b restore /dev/sda2 /recovery/trixorg.gz

1. Destination partition should be larger or same of original file even though

Space occupied is less.

2. While saving image destination partition should be mounted where you are about to store image otherwise temp error.

 

Save and Restore using fsarchiver

To save to image:

Fsarchiver –j2 –v savefs fs_trixbox /dev/hda2

To restore from image

fsarchiver –j2 –v restfs fs_trixbox.fsa id=0,dest=/dev/sda1

Friday, March 27, 2015

Packeth Patch to display All interfaces ( Down and Non IP Assigned)

Src/callbacks.c
static GtkWidget *file_menu = NULL;
@@ -2167,6 +2167,11 @@ on_Interface_button_clicked
        struct ifreq        IfcBuf[512];
        struct ifreq        *pIfr;
        int num_ifreq;
+
+       struct if_nameindex *pif;
+       struct if_nameindex *head;
+       head = pif = if_nameindex();
+
        int i, fd, length;
        char buff[100];
        char *ptr;
@@ -2201,6 +2206,16 @@ on_Interface_button_clicked
        ptr = buff;
+       while (pif->if_index) {
+                       snprintf(ptr, 100, "%s", pif->if_name);
+                        glist = g_list_append(glist, ptr);
+                        ptr = ptr + strlen(pif->if_name) + 1;
+                        length = length + strlen(pif->if_name) + 1;
+                       pif++;
+
+       }
+       /*
+
        for ( pIfr = Ifc.ifc_req, i = 0, length = 0 ; i < num_ifreq; pIfr++, i++ ) {
                if ( (length + strlen(pIfr->ifr_name) + 1) < 100) {
                        snprintf(ptr, 100, "%s", pIfr->ifr_name);
@@ -2211,7 +2226,8 @@ on_Interface_button_clicked
                else
                        break;
        }
-
+       */
+       if_freenameindex(head);
        gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist) ;
        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), iftext);

Monday, March 23, 2015

X11 on Non X11 Server remotely ( MobaXterm)

I had a server running that was not running a X-server , so i couldn't run any Graphical application

also i didn't had root access to do so , So i downloaded ( MobaXterm ) on windows, which has embedded X-server ( not X-client)

and u can run Graphical on Windows via SSH. Also supports SFTP so if you edit any file its save on the

server.

 

image

 

Just You have to set DISPLAY on remote machine as

exporrt DISPLAY=IP_OF_WINDOWSPC>:0.0

Also has Cygwin, where u can install packages through apt-get install <package>

Check some of the exiting features.

http://mobaxterm.mobatek.net/features.html

Wednesday, March 4, 2015

Cheap USB Remote control for PC and RaspberryPI

I purchased a USB remote control from Ebay , Costing Just rs 340

http://www.ebay.in/itm/New-PC-Remote-Controller-With-USB-Receiver-for-Windows-Laptops-/121450953360?ssPageName=ADME:L:OC:IN:3160

clip_image002

Just connect the Reciever to Laptop or Rasperry Pi. For windows 7 it creates two device entry

1.HID generic mouse

2.HID genric Keyboard

Now if remote u can use it as mouse+ keyboard, increase decrease volume..etc

 

Raspberry Pi with XBMC OS

No configuration required , Just Plug and Play. These remotes are recognized as a keyboard/mouse device. Just ensure that “Remote control sends keyboard presses” is enabled under “Input Devices”.

clip_image004

Raspberry Pi Remote Control Settings

Featured Post

XDP - Getting Started with XDP (Linux)