Email from BASH script

I did looking for a solution to inform to me when a distributed router is reseted/rebooted, and add to it some information, like public IP, GEO position and hostname of the router.

And I found this solution, a script into the boot order that send to me a email with this information.

root@rasp3:/home/pi# cat sendMail.sh
#!/bin/bash
myPublicIP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
echo $myPublicIP
myGPSposition=$(geoiplookup $myPublicIP)
echo $myGPSposition
quienSoy=$(whoami)
echo $quienSoy
localHost=$(hostname)
echo $localHost
dt=`date '+%d/%m/%Y_%H:%M:%S'`
echo $dt
run=$(mail -s "Server $localHost rebooted" iphone@walii.es <<< "El router $localHost se ha conectado desde:\n IP: $myPublicIP \n Posicion GPS: $myGPSposition \n Fecha $dt")

 

and the next code into the init folder.

/etc/init.d/sendMailRun

case "$1" in
start)
echo -n "SEND MAIL"
/home/pi/SCRIPTS/sendMail.sh & >/dev/null
echo "."
;;
stop)
echo -n "SEND MAIL NO NEEDED"
echo "."
;;
restart)
echo -n "SEND MAIL AGAIN"
/home/pi/SCRIPTS/sendMail.sh & >/dev/null
echo "."
;;
*)
echo "Usage: /etc/init.d/radius {start|stop|re-send}"
exit 1
esac

exit 0

 

ESP2866 Distance

Here we have a demo of the distance that will reach the standard module.

The AP wifi is a APPLE TIME CAPSULE, and the distance is near to 40 mtrs.

IMG_3913

 

The green light describe how we have a correct connection link and the ping delay is into 5 and 50ms.

Greetings.

WIFI to Serial module ESP2866

This is a new module, that will help us to communicate with our ARDUINOS or PINGUINOS modules.

Is like a modem, by all the people that use some time ago the well know US-ROBOTIC, know the AT commands, and the easy way to use it.

The module showed is a BASIC model, but the distance that reach is perfect for domotic or smart home.

Unknown-9

 

The PINOUT

esp8266_schematic

The power supply never will be UP of 3,62Volts

After of some days testing I will say that is recommended that you install a resistor from VCC to CH_PD, to make UP this pin. With an 1k resistor will be perfect.

 

 

The next example code only make a GET of a WEBPAGE, if we run a TCPDUMP in the middle of the NETWORKS we will capture the request.

This code will be compatible with any project ARDUINO or PINGUINO

#define SSID “Walii” //your wifi ssid here
#define PASS “ffffffffff” //your wifi wep key here

#define DST_IP “164.138.31.203” //baidu.com
#define HOST “pinguino.walii.es”

char myChar;

void setup()
{
pinMode(9, OUTPUT);
pinMode(13, OUTPUT);

//blink led13 to indicate power up
for(int i = 0; i<15; i++)
{
digitalWrite(13,HIGH);
delay(50);
digitalWrite(13,LOW);
delay(50);
}

// Open serial communications for WiFi module:
Serial.begin(115200);
// Set time to wait for response strings to be found
Serial.setTimeout(5000);
delay(100);

//test if the module is ready
Serial.println(“AT+RST”);
if(Serial.find(“ready”))
{
delay(1000);
//connect to the wifi
boolean connected=false;
for(int i=0;i<5;i++)
{
if(connectWiFi())
{
connected = true;
break;
}
}
if (!connected)
{
//die
while(1);
}

delay(5000);
//set the single connection mode
Serial.println(“AT+CIPMUX=0”);
}
else
{
delay(100);
}
}

void loop()
{
String cmd = “AT+CIPSTART=\”TCP\”,\””;
cmd += DST_IP;
cmd += “\”,80″;
Serial.println(cmd);
if(Serial.find(“Error”)) return;
cmd = “GET /status HTTP/1.0\r\nHost: “;
cmd += HOST;
cmd += “\r\n\r\n”;

Serial.print(“AT+CIPSEND=”);
Serial.println(cmd.length());
if(Serial.find(“>”))
{
}
else
{
Serial.println(“AT+CIPCLOSE”);
delay(1000);
return;
}

Serial.print(cmd);

delay(500);
//Serial.find(“+IPD”);
while (Serial.available())
{
char c = Serial.read();
delay(50);
}

delay(1000);
}

boolean connectWiFi()
{
Serial.println(“AT+CWMODE=1″);
String cmd=”AT+CWJAP=\””;
cmd+=SSID;
cmd+=”\”,\””;
cmd+=PASS;
cmd+=”\””;
Serial.println(cmd);
delay(2000);
if(Serial.find(“OK”))
{
return true;
}
else
{
return false;
}
}

 

 

TCPDUMP capture.

22:25:46.492679 IP 10.10.10.127.60604 > 164.138.31.203.80: Flags [.], ack 5761, win 638, options [nop,nop,TS val 108106608 ecr 2454109009], length 0
22:25:46.493147 IP 164.138.31.203.80 > 10.10.10.127.60604: Flags [.], seq 5761:7201, ack 73, win 905, options [nop,nop,TS val 2454109009 ecr 108106599], length 1440

 

 

 

 

Specifications and Features

  • Default Baud Rate: 115200
  • 802.11 b / g / n
  • Wi-Fi Direct (P2P), soft-AP
  • Built-in TCP / IP protocol stack
  • Built-in TR switch, balun, LNA, power amplifier and matching network
  • Built-in PLL, voltage regulator and power management components
  • 802.11b mode + 19.5dBm output power
  • Built-in temperature sensor
  • Supports antenna diversity
  • “Off” leakage current is less than 10uA
  • Built-in low-power 32-bit CPU: can double as an application processor
  • SDIO 2.0, SPI, UART
  • STBC, 1×1 MIMO, 2×1 MIMO
  • A-MPDU, A-MSDU aggregation and the 0.4 Within wake
  • 2ms, connect and transfer data packets
  • Standby power consumption of less than 1.0mW (DTIM3)

nRF24L01

nRF24L01 PINOUT

pinoutNRF24L01

images-3

MANUAL DETAIL

nRF24L01_Product_Specification_v2_0

Raspberry pi

Here I will let a continues update information regarding all time of PINOUT.

Starting with

RASPBERRY  B

 

 

gpio-pinout raspberry pi B

 

 

Raspberry pi A B & B+

Raspberry-Pi-GPIO-pinouts

 

 

Facebook Like Add
Google PLUS ONE
De donde me visitan
Publicidad
Calendario de Posts
December 2016
M T W T F S S
« Nov    
 1234
567891011
12131415161718
19202122232425
262728293031