Skip to main content

FLL EV3 Robot

This blog post is about our current EV3 robot we're planning to use in the 2023/2024 FLL competition. Some features: 2 large motors for steering. 2 medium motors for attachments.  2 colour sensors for picking up the white and black lines, also used for line squaring. 1 gyro sensor. To enable attachments to be changed as quickly as possible we're using gravity to keep the gears connected, i.e. you don't need to fasten anything to the robot. Every attachment has 2x 12 tooth double bevel gear (part 32270) which comes in contact with the 2x 20 tooth double bevel gears (part 32269) on the robot. The medium motors are horizontally aligned on the robots, but we use 12 tooth double bevel gears to convert that to vertical alignments. These in turn are connected to 20 tooth double bevel gears, and the attachments in turn connect to these 20 tooth double bevel gears with their 12 tooth double bevel gears.  The complete robot is modelled in Bricklink Studio 2 . You can download the rob

Bash script to send emails

It is possible to send emails directly from a bash script instead of using a third party email program.

My first attempt was to use netcat to send data to the SMTP server. Netcat does almost the same as telnet, but telnet doesn't support input redirection (i.e. you can't send commands from a text file to the client - you have to manually type it).

The problem with netcat is that it sends everything in a block - instead of waiting for a response from the server before sending the next command. In most cases it will work, but I did get instances where the email was not sent.

Bash has a feature where you can open a TCP/IP connection directly from a script. It allows you to read & write to it, giving you all you need to interface with a SMTP server.

See the code below for the send_mail procedure I'm using:


#!/bin/bash

send_mail () {
  # $1 smtp server
  # $2 smtp port
  # $3 address from
  # $4 address to
  # $5 subject
  # $6 body

  if [ $# -ne 6 ]; then
    echo "send_mail needs 6 parameters"
    return $false
  fi

  exec 3<>/dev/tcp/$1/$2
  read -u 3 response
  echo $response

  echo -en "HELO $1\r\n">&3
  read -u 3 response
  echo $response

  echo -en "MAIL FROM: $3\r\n" >&3
  read -u 3 response
  echo $response

  echo -en "RCPT TO: $4\r\n" >&3
  read -u 3 reponse
  echo $response

  echo -en "DATA\r\n" >&3
  read -u 3 response
  echo $response

  echo -en "From: $3\r\nTo: $4\r\nSubject: $5\r\n\r\n$6\r\n.\r\n" >&3
  read -u 3 response
  echo $response

  echo -en "QUIT\r\n" >&3
  read -u 3 response
  echo $response

  exec 3>&-

  return $true
}

send_mail "smtp.anywhere.com" 25 "from@anywhere.com" "to@anywhere.com" "Subject" "Body"

So first it opens a TCP/IP connection to file descriptor 3 with the exec command. Why file descriptor 3? Because unix has the following standard file descriptors:
0: standard input (stdin)
1: standard output (stdout)
2: standard error (stderr)

File descriptor 3 is the first number we can use for our own purpose - but you can safely change that to any other number if you wish.

After opening the connection you can read & write to this file descriptor. 
To read we use the read command with -u to read from the specific file descriptor. This will wait for a complete response back from the server (reads a whole line).

To write we do with a normal echo command redirected to file descriptor 3. We use -en to enable interpretation of backslash escapes and to disable the output of a trailing new line. This is because the official SMTP requirements state you need a carriage return (\r) and linefeed (\n) after each command - so we send both (\r\n) after each command.

So after opening the connection, we first read a line from the SMTP server to get the official greeting.

Then we send a HELO command (with username equal to the server address - this usually works, but you'll have to modify if your server needs a username & password). After that we wait for a response back from the server, usually it will send a welcome message. Note that we do NOT check for any errors the server might return - we just assume everything will be OK. For debugging purposes we echo all the server reponse back to the screen, but if you run this as a background process you won't see these messages.

To initiate a new message we send the MAIL FROM command with a valid from email address. Make sure you're using a valid address, if not the server will reject this command.

For recipients we only support one address at this stage with the RCPT TO command. To send it to more recipients you'll need multiple RCPT TO commands.

The actual email contents is sent after a DATA command. This section should contain the SMTP headers (i.e. To, From, Subject lines, but can contain a lot more), an empty line, then the body of the email, terminated by a dot on a seperate line.

The server should then send the email and come back with a response. After that we close the session by issuing a QUIT command, then we close the TCP/IP connection with the exec command.

Known limitations - but these can be addressed:
  1. No error checking
  2. Only supports one recipient
  3. No support for attachments

Comments

Popular posts from this blog

Installing Lego Digital Designer (LDD) on Windows 10

If you're using Windows 10 18.09 or later and try to install Lego Digital Designer (LDD) 4.3.11 you'll probably get an installation error for Adobe Flash Player. However, there is an easy way around it: Download the installation file for LDD 4.3.11. Rename the .exe file to .zip. If you don't see the .exe extension in Explorer, go to "View - Options" on the Explorer menu, then under the "View" tab deselect the "Hide extensions for known file types". Open the zip file with Windows Explorer. Copy all files in the zip to another directory on your computer. In the new folder: Delete install_flash_player_active_x.exe. Copy OpenGLChecker.exe and rename it to install_flash_player_active_x.exe. Run LDDSetup.exe. In short the installer will execute install_flash_player_active_x.exe during the installation process, but all it does now is to execute the same logic as what OpenGLChecker does. In theory you can run any .exe that will not retu

OpenWRT 3G connection checker & logger

A 3G connection is normally not very stable - so we need something to periodically check it & reconnect when needed. I also wanted a summary email at the end of each day with the total traffic per client. I'm using the following settings/scripts: Edit /etc/crontabs/root (create if not existing): # send stats & disconnect 3G at 23:00 everyday. # check the connection every 5 minutes between 5:00 and 23:00 and reconnect if needed # reboot at 5:00 if /tmp/stats.msg doesn't exist - will be sent in checkconnect */5 5-22 * * * /usr/bin/checkconnection 0 5 * * * if [ ! -s /tmp/stats.msg ]; then reboot ; fi 0 23 * * * /usr/bin/sendstats && ifdown wan The first line will run /usr/bin/checkconnection every 5 minutes between 5:00 and 22:59. Then at 23:00 the  day's statistics will be emailed and the 3G connection disconnected. The next morning at 5:00 it first checks if the email was sucessfully sent at 23:00, if so it will reboot the router (seems to be m

Windows Hyper-V Server 2019

This post will explain how to use the free Hyper-V Windows 2019 Server version. This version doesn't come with any GUI interface as provided in the full Windows 2019 Server version. Instead it comes with a character interface, but with the help of some third party tools you can easily get a fully functional Hyper-V server for free. The following will be assumed: You have a dedicated server connected to a network and you want to install Hyper-V 2019 on this server to run Virtual Machines and/or act as a file server. You have physical access to this server to do the installation. You have another machine connected to the same network to do remote management, running a recent version of Microsoft Windows. You don't want to join a domain or use Active Directory. You can do this if you want to, but this is not included in this post. First you'll need to download the Hyper-V 2019 ISO from  https://www.microsoft.com/en-us/evalcenter/evaluate-hyper-v-server-2019 . You’ll