arduenna

arduenna is an automatic directional-antenna alignment software using Arduino. arduenna consists of arduenna.sh (bash script for linux) and arduenna.ino (program running on Arduino). Hardware: linux PC with external wLAN-adapter and directional-antenna attached to it. Arduino Board (Uno, Mega, etc.), LCD (keypad) shield (optional), Servo.

arduenna is intended to track a directional-wifi-antenna to the direction of the strongest signal of a wifi access point. This is especially useful on a slightly moving (sailing) vessel on anchor where directional antennas are normally more or less useless due to the vessels movement.

to do: Find larger servo. At the moment the available servo is to small for the attachment of a directional-wlan-antenna…

license: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

arduenna software on arduino and laptop

arduenna software running on arduino and laptop

arduino steering the servo (no directional wlan antenna attached to servo so far)

arduino steering the servo (no directional-wlan-antenna attached to servo so far)

bash script (linux):


#!/bin/bash
# arduenna v1.0, 16/01/27, Dr. Sven Seren
# arduenna is an automatic directional-antenna alignment software via arduino
# arduenna consists arduenna.sh (linux) and arduenna.ino (arduino)
# hardware: linux pc with external wlan-adapter and directional antenna attached to it
# arduino uno or arduino mega, LCD (keypad) shield (optional)

### variables and definitions ###

LOST=1

### text colours ###

RED=“\033[1;31m“
GREEN=“\033[1;32m“
YELLOW=“\033[1;33m“
BLUE=“\033[1;34m“
ENDCOLOR=“\033[0m“

### info ###

clear
echo
echo -e $RED“=====================“$ENDCOLOR
echo -e $YELLOW“=== arduenna by Ø ===“$ENDCOLOR
echo -e $RED“=====================“$ENDCOLOR
echo
echo -e $BLUE“automatic directional-antenna alignment via arduino“$ENDCOLOR
echo

### main ###

# echo -e $GREEN“[+] wlan NIC# ? [enter] = default (2)“$ENDCOLOR
# read -n 1 IFACE
# echo
# if [[ $IFACE == “ ]]; then
#  IFACE=2
# fi

IFACE=$(iwgetid | cut -b 1-5)
if [[ $IFACE == “ ]]; then
echo -e $YELLOW“no connection available, connect and press [enter]“$ENDCOLOR
read -n 1
clear
./arduenna.sh
else
echo -e $YELLOW“using NIC: $IFACE“$ENDCOLOR
fi
echo

echo -e $YELLOW“initializing arduino communication…“$ENDCOLOR
stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
if [ „$?“ != „0“ ]; then
echo -e $YELLOW“unable to connect to arduino, connect and press [enter]“$ENDCOLOR
read -n 1
clear
./arduenna.sh
else
echo -e $YELLOW“connection to arduino initialized“$ENDCOLOR
fi
echo
sleep 1;

while [ true ]; do
DECIBEL=$(iwconfig $IFACE | grep ‚Signal level=‘ | cut -b 44-47)
# QUALITY=$((2*($DECIBEL+100)))
if [[ $DECIBEL == “ ]]; then
echo -ne $YELLOW“connection lost, waiting for signal…\033[0K\r“$ENDCOLOR
echo $LOST > /dev/ttyACM0
else
echo -ne $YELLOW“signal [dB]: $DECIBEL\033[0K\r“$ENDCOLOR
# echo -ne $YELLOW“signal [dB and %]: $DECIBEL\033[0K $QUALITY\033[0K\r“$ENDCOLOR
echo $DECIBEL > /dev/ttyACM0
fi
sleep 1;
done


 

arduino program:


/*
arduenna v1.0, 16/01/27, Dr. Sven Seren
arduenna is an automatic directional-antenna alignment software via arduino
arduenna consists of arduenna.ino (aduino) and arduenna.sh (linux)
hardware: arduino uno or arduino mega, LCD (keypad) shield (optional), servo
servo (continuous rotating) on pin A1
*/

// definition of libaries
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#include <Servo.h>
Servo servo;                                                                  // define servo

// definition of constants and variables
#define servo_pin A1                                                   // pin for servo
#define servo_step_width 25                                      // time (us) servo is on
#define servo_delay 1000                                            // waiting time (us) after servo movement until measurement

int i=1;                                                                           // counter variable

int serial_value=1;
int pin_value_actual=1;                                                // variables for signal maximum detection
int pin_value_left=1;
int pin_value_right=1;
int pin_value_center=1;

void setup() {
Serial.begin(9600);                                                      // start serial connection library
lcd.begin(16, 2);                                                            // start LCD library
lcd.clear();
servo.attach(servo_pin);                                               // attach servo to pin
servo_stop();                                                                  // stop servo movement
display_banner();                                                          // show software info on LCD
}

// display banner
void display_banner () {
lcd.clear();
lcd.setCursor(0, 0); lcd.print(“ blue-felix.de“);
lcd.setCursor(0, 1); lcd.print(“ arduenna v1.0″);
delay(2000);
lcd.clear();
}

// motion routines for servo (continuous rotation): 0 rotate in one direction, 180 in opposite direction, 90 stop
int servo_step_left(int n) {
for (int i=1; i<=n; i++) {
servo.write(100);
delay(servo_step_width);
servo.write(90); }
}

int servo_step_right(int n) {
for (int i=1; i<=n; i++) {
servo.write(80);
delay(servo_step_width);
servo.write(90); }
}

void servo_stop() {
servo.write(90);
}

// function for tracking antenna signal with servo
int servo_track_signal(int n) {
lcd.setCursor(13, 1); lcd.print(„<< „);
servo_step_left(n);
delay(servo_delay);
pin_value_left=Serial.parseInt();
lcd.setCursor(13, 0); lcd.print(pin_value_left);

lcd.setCursor(13, 1); lcd.print(„>> „);
servo_step_right(n);
delay(servo_delay);
lcd.setCursor(13, 1); lcd.print(„>> „);
servo_step_right(n);
delay(servo_delay);
pin_value_right=Serial.parseInt();
lcd.setCursor(13, 0); lcd.print(pin_value_right);

lcd.setCursor(13, 1); lcd.print(„<< „);
servo_step_left(n);
lcd.setCursor(13, 1); lcd.print(„<> „);
delay(servo_delay);
pin_value_center=Serial.parseInt();
lcd.setCursor(13, 0); lcd.print(pin_value_center);

if (pin_value_left > pin_value_center) {
lcd.setCursor(13, 1); lcd.print(„<<<„);
servo_step_left(n);
}
if (pin_value_right > pin_value_center) {
lcd.setCursor(13, 1); lcd.print(„>>>“);
servo_step_right(n);
}
}

// function for serial communication with linux bash script and call of function servo_track_signal()
void check_serial()
{
int n;
if (Serial.available() > 0)
{
serial_value = Serial.parseInt();
if (serial_value == 1)                                                                                         // check for antenna signal present
{ lcd.clear(); lcd.setCursor(0, 1); lcd.print(„wlan lost!“); servo_stop(); delay(500); lcd.clear();}
else
{ lcd.setCursor(0, 0); lcd.print(„signal [dB]“);
// lcd.setCursor(0, 1); lcd.print(„i=“); lcd.setCursor(2, 1); lcd.print(i);      // display loop counter
if (i==1) { n=5; }                                                                                            // make one larger movement after 7 fine movements
if (i>1 && i<8) { n=1; }
if (i>=8) { i=0; }
servo_track_signal(n);
i=i+1;
}
}
else {lcd.clear(); lcd.setCursor(0, 1); lcd.print(„no data!“); servo_stop(); delay(500); lcd.clear();}   // check for linux script running
}

// main loop
void loop() {
check_serial();
delay(500);
}