Edimax EW-7811Un Wifi Adapter on FreeBSD Server

Servers are awesome. They’re like huge hunks of metal and machinery that can perform duties like the big supercomputers they are.

I acquired a massive, old, and clunky Dell server from one of the UTW dudes, of which I have now named Big Bertha. She’s a feisty one, I tell ya.

Because I want to have her running 24/7 in my garage or closet, I had to get a WiFi adapter working so she could run without ethernet.

Through a post on the FreeBSD forums, I determined the driver that worked alongside the Edimax 7811Un adapter was urtwn0. I believe you can also run these in the terminal if you’re still not sure, and it’ll return a driver:
For FreeBSD 10 and under:
ifconfig | grep -B3 -i wireless

For FreeBSD 11 and higher:
sysctl net.wlan.devices

Once determined, it was a matter of putting some lines in config files.

In /etc/wpa_supplicant.conf, put in:

network={
ssid="myssid"
psk="mypsk"
}

Where myssid is the name of your network, and mypsk is the password.

In /etc/rc.conf, put:

wlans_urtwn0="YES"
ifconfig_wlan0="WPA SYNCDHCP"

Where urtwn0 is the replaced by the driver that works with your server.

Finally, put the code below in /boot/loader.conf:

if_urtwn_load="YES"

And because I knew the edimax adapter used a Realtek chip, I added this to the same loader file:

legal.realtek.license_ack=1

After that, reboot your server OR run service netif restart.
If everything works correctly, you should be able to ping google.com or ping 8.8.8.8 and get responses back.

{thallia}

p.s. I apologize for the lack of code blocks, I'm looking into plugins to get that working.

Advertisements

ESP32 with Blynk – Lighting an LED over wifi

Recently, my friend Gector lent me a new microcontroller called the ESP32. They are fairly new to the market and have super cool wifi, bluetooth, and networking capabilities! Since I’ve been in the area of networking projects for the past few days, I thought I’d play around with one.

To set it up, I followed Sparkfun’s tutorial.

First, make sure you have the Arduino IDE installed on your OS.

Next, make a directory in your filesystem where you want all the ESP32 stuff to go.
Then run all these lovely instructions from this github documentation:
sudo usermod -a -G dialout $USER && \
sudo apt-get install git && \
wget https://bootstrap.pypa.io/get-pip.py && \
sudo python get-pip.py && \
sudo pip install pyserial && \
mkdir -p ~/Arduino/hardware/espressif && \
cd ~/Arduino/hardware/espressif && \
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
cd esp32 && \
git submodule update --init --recursive && \
cd tools && \
python get.py

Since I didn’t have Arduino.app installed in /Applications/ on my computer, I didn’t have to change some other aspects of my installation. But if you do have that setup, don’t forget to run this:
cd /Applications/Arduino_*/Contents/java/hardware/
mkdir -p espressif && \
cd espressif && \
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
cd esp32 && \
git submodule update --init --recursive && \
cd tools && \
python get.py

Once done, cd /esp32/tools and run python get.py.

Now you can connect your ESP32 to your computer!
In the Arduino IDE, under Tools, select ESP32 Dev Module as your board. Make sure you have the right Port selected, too.
My setup looks like this:
Screenshot from 2017-12-03 16-42-47.png

Once finished, I installed the Blynk app on my iPhone. Sign up with an email and password, and create a New Project.

Give your project a name, choose the ESP32 as the device and WiFi as the connection type. Tap create project when you’re finished!
This will direct you to a black screen. Tap anywhere to add a “widget”, where you’ll select the Button option. It’ll add the button to your screen. Tap on it to edit the settings.

In settings, in the empty PIN field, put Digital GP21. Save/Exit the settings, and you’re almost finished.

Before we can see any action, we’ve got to download the Blynk Arduino Library.
On the Blynk Github Page, you can clone the repo into your Arduino folder, or you can download the ZIP file and extract it into the Arduino folder.

In the Arduino IDE, go to Sketch > Include Library > Blynk and the library should be imported.

After that, download the sample code found in this tutorial: http://www.instructables.com/id/Use-ESP32-to-Control-LED-With-Blynk-Via-WiFi/

Then replace “Your auth token” with the authorization code sent to you in your email for the project in this code block:
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Your Auth Code Here";

And again in this line farther down in the file:
Blynk.begin("Your Auth Code Here", ssid, pass);

Near the beginning of the file, add your Network WIFI name and password where it says:
char ssid[] = "Network name";
char pass[] = "Network password";

Save the file and load it into the Arduino IDE as a sketch, but don’t run it yet.

Make sure your ESP32 is plugged into the computer. Now stick it into a breadboard and find an LED. Plug the LED’s long (anode) led into Pin 21 of the ESP32, and the short (cathode) leg into pin GND. There are GPIO charts you can find on the interwebs if there aren’t any names on your board.

The moment of truth comes…upload the code onto the ESP32 and open the Serial Monitor (Tools > Serial Monitor). If all goes well, your board should connect to your wifi and say something that looks like this:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078ad0
Connecting to HOME-D7EF-2.4
..WiFi connected
[1075] Connecting to HOME-D7EF-2.4
[1075] Connected to WiFi
[1075] IP: 10.0.0.175
[1075]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.5.0-beta on ESP32

[5001] Connecting to blynk-cloud.com:8442
[5241] Ready (ping: 116ms).

If you run into trouble, don’t worry. If it can’t upload the code due to permissions issues, open a terminal and run:
sudo chmod 666 /path/to/port

If you get an error about an invalid auth code like I did, make sure all your devices are on the same network as the ESP32, generate a new auth code, and double check your setup.
If you’re still having issues, take a look at Sparkfun’s tutorial I mentioned at the beginning of this article. They have a few resources I may not have mentioned.

In the Blynk app press the Play triangle in the top right hand corner. It should tell you whether or not the WiFi LED is connected or not, and once it is, go ahead and press your button, and the LED will light up!

So much excitement for something so small and cute, but it’s sure fun to play with.

{thallia}

Raspberry Pi IRC Server

As UTW is growing, we’re getting closer and closer to using a better platform for chatting (we’ve been using Discord up to this point, which has been fantastic). To get practice in networking ideas and to use my old Raspberry Pi B+, I decided to set up a small IRC server.

I found this tutorial at Pi My Life Up: https://pimylifeup.com/raspberry-pi-irc-server/

It covered the basics, but not all of them, so I thought I’d make a tutorial and document what I’ve done as well.

As always, I started with sudo apt-get update and sudo apt-get upgrade.

Next, I installed a software called Ircd-Hybrid, โ€œA lightweight, high-performance internet relay chat daemon”. Perfect for the raspberry pi!

The next step requires you to make a password, and have something to copy/paste it, or have something to write it down.
Using /usr/bin/mkpasswd password, replace “password” with your preferred and secret password, hit enter, and it should return an encrypted, scrambled version of your password. COPY AND SAVE THIS, we’ll need it later!

Next you have to configure what you actually want your server to do, say, be named, etc. To access the configuration file, run:

sudo nano /etc/ircd-hybrid/ircd.conf

There’s a lot to look at in this config. It overwhelmed me at first, but as long as you take it one block at a time, it’s fairly easy to understand.

In the first block, serverinfo {, find the first line:

name = "hybrid8.debian.local";

And change it to:

name = "underthewire.irc";

In my case, I changed the name to Under the Wire, since that’s the name of our group. You can change it to whatever name you wish ๐Ÿ™‚

Next, find:

description = "ircd-hybrid 8.1-debian";

And change it to be similar to this:

description = "Raspberry Pi UTW IRC Server";

This is the description of what the server is, and it’ll display this when you connect to the server in your IRC client (I use weechat).

Find:

network_name = "debian";
network_desc = "This is My Network";

Replace with:

network_name = "underthewire";
network_desc = "This is the unofficial test run UTW IRC Server";

This describes the network that your server is going to run on.

Now skip down past the admin, log, and class blocks until you find the listen block.

In listen, change the host line to your local IP address.

Next, find the auth block.
in:
user = "*@127.0.0.1";

You can replace it with:
user = "*@*";
to allow all IP addresses to be able to access the server.

Within the operator block, find:

user = "*@192.0.2.240/28";

and change it to:

user = "*@*";

Finally, find the password line.

password = "xxxxxxxxxxxxx";

Replace the xs with the encrypted password that you generated for your server near the beginning of this post.

You should be done now, so Ctrl-x your way out, y to save the changes.

Now we’ll edit the MOTD file, which will appear to the users once they connect to your server!
Using sudo nano /etc/ircd-hybrid/ircd.motd to get there. You can delete all the contents of the file and write your own messages, or keep the Debian Swirl and write over the words, or leave it as is.

I kept the debian swirl and wrote down the rules and inside jokes of our group. ๐Ÿ™‚

After saving and exiting, run sudo /etc/init.d/ircd-hybrid restart to restart the server and implement all your changes.

Connecting to the server was the challenging part, but it’s fairly simple once you understand how to port forward from your router.
Since I am on my network, I hypothesized that I can’t connect to the server from the public IP since I’m already in the network. But I’d still have to port forward so other people can join with my public IP.

My ISP (internet service provider) is Xfinity/Comcast, so with a few screenshots I’ll demonstrate how to port forward on their website.

First, you have to find your local IP address, in which mine was 10.0.0.1. If you enter your local IP into your browser like so:

10.0.0.1

It should take you to the router gateway. You’ll be asked to login. The username default for Comcast/Xfinity is admin, and the default password is password. It took me way too long to figure that out…but once I did, I changed the default password.

After you’ve logged in, it should look something like this on the top lefthand side:
Screenshot from 2017-12-02 18-57-15

Click on Advanced, and the drop down menu will have a Port Forwarding option.

That will take you to a screen that looks like this:
Screenshot from 2017-12-02 19-02-16.png

Make sure you’ve clicked on Enable.
After that, click on Add Service, which will load a scary screen like this:

Screenshot from 2017-12-02 19-04-19.png

For Common services there are many options depending on what your network can do, but I left it as other for my goal.

The Service Name is where you enter a name or label for whatever this port forward will be used for. I wrote Raspberry Pi UTW IRC.

The Service Type I left as TCP/UDP, because I didn’t know for sure which one it would need. If you know for sure, you can choose that specific option.

In Server IPv4 Address you place the IP address that points to the device the server is on. If you have a UNIX-based system, you can enter hostname -I into the terminal and it should return its IP address.

I skipped over the Ipv6, and in the start port, 6667 and end port I put 6667. That seemed to be the most default IRC port that I saw. Once done, click save, and you should be done! If the changes don’t take effect immediately, a router reboot wouldn’t hurt anything.

Finally, we can try connecting!

I use weechat as my IRC client. Connecting with that (as me), I ran:

/server add nameoftheircserver local-ipaddress-of-device
It looked like this for me:
/server add underthewire 10.0.0.xxx
(where the x’s were numbers)

Then:
/connect underthewire
And it should run!

Now if you wanted to allow other people to access the IRC server, the syntax looks exactly the same, but they put your public IP address in place of the local IP. You can find your public IP address at ipchicken.com

And that’s it! Super easy, I finished it in 2hrs with researching included. Thanks to uelen, fouric, and Gector in UTW for answering my questions as I was going through this project.

As for next steps, I’m going to put an SSL certificate on the server to make it secure, and hopefully upgrade or remake a new server once I understand more how the process works. ๐Ÿ™‚

{thallia}

ArkenPi – Origins (hardware)

Final list of materials:

  • Raspberry Pi 3 Model B
  • MicroSD Card (32GB)
  • Adafruit PiTFT 3.5″ PLUS Touchscreen
  • Lithium-Ion Polymer Battery (1200mAh)
  • Wireless Bluetooth Keyboard
  • 5.5V to 3.3V step down converter
  • Adafruit Powerboost 1000c
  • Female USB Connectors
  • Male USB Connectors
  • MicroUSB POWER ONLY Cord (short)
  • Power switch
  • Wifi Adapter (optional)
  • 2x 3mm LEDs
  • 2x 200ohm resistors
  • A 3D Printed case OR hack your own out of hard drive cases

Tools:

  • soldering station
  • pliers (round nose)
  • tweezers
  • knife
  • wire cutters
  • solder
  • hookup wire (stranded recommended)
  • electrical tape
  • hot glue gun + glue
  • (opt) helping hands
  • patience

Before assembling anything, I had to get the Pi3 to boot with the Adafruit PiTFT plus, which was a pain in the butt. The adafruit website declared,

“The display uses the hardware SPI pins (SCK, MOSI, MISO, CE0, CE1) as well as GPIO #25 and #24. GPIO #18 can be used to PWM dim the backlight if you like. All other GPIO are unused.”

I found that to be false info. I scratched my head trying to figure out how to find which pins were being used and which ones weren’t, and I came up with the brilliant and monotonous idea of connecting 40 jumper wires from the PiTFT to the Pi 3. I disconnected each pin one at a time to see if it would boot correctly, then removed the jumper wire if it wasn’t needed. In thirty minutes, I had the right pins to get the Pi to boot onto the TFT.

https://openclipart.org/image/2400px/svg_to_png/280972/gpiopinsv3withpi.png

Using the chart above helped a lot (credit to whoever’s chart it is), and here are the GPIO pin numbers I came up with, and their functions:

pin 1 - 3.3V PWR

pin 2 - 5V PWR

pin 9 - GND

pin 18 - GPIO24 (GPIO_GEN5)

pin 19 - GPIO10 (SPI0_MOSI)

pin 21 - GPIO9 (SPI0_MISO)

pin 22 - GPIO25 (GPIO_GEN6)

pin 23 - GPIO11 (SPI0-_CLK)

pin 24 - GPIO8 (SPI_CE0_N)

pin 26 - GPIO7 (SPI_CE1_N)

pin 27 - ID_SD (I2C EEPROM)

pin 28 - ID_SC (I2C EEPROM)



Assembly:

img_5217

I had to wait three to four days for the case to finish drying, but boy, was it worth it!

I started by desoldering the Li-Po battery from the inside of the bluetooth keyboard, attaching to the leads the 5.5V to 3.3V step down converter.

img_5183

The Vout of the step down I soldered go to the 5V and GND through-holes on the Adafruit Powerboost 1000c.

I left the original USB port on the adafruit powerboost and permanently soldered it to the board.

img_5184.jpg

I figured it would be easier to use a well off microUSB cord than to play around with making my own with hookup wire. Fortunately, I had an older (and shorter) microUSB cord that was just for power, not data transfer, so I used that. I wasn’t able to fit the microUSB cord through the holes in the case, so I stripped off the plastic cover to reveal the wires, and I soldered those onto the Pi. I checked with a multimeter which pads were 5V and GND, so I knew where to solder.

img_5185img_5172.jpg

In the end, I decided to forget attempting to get 12 hookup wires through the holes in the case, and I resoldered a 2×20 GPIO header onto the Pi and connected the PiTFT on top of those (like it was intended to be used).

In the case, I drilled two holes for a power light and a low battery light. All of these I soldered from the adafruit powerboost, so I rigged up my 3mm LEDs.

img_5186
I wrapped a 200ohm resistor around the stripped wire, soldered the two joints, then trimmed the wires.

I accidentally burned out an LED before realizing that the resistor was in parallel, therefore not allowing the full resistance to get to the LED. I trimmed the wire after that. (below)

img_5190
My solder joints are pretty ugly, I know. But I promise I made them nicer! I also covered that part of the wire in electrical tape.

img_5191

Next was to solder hookup wire to the male USBs:

I made each one a different length, since the female USBs were different lengths away.

img_5218.jpg
Hot gluing the solder joints was a life saver for me, because if you bent the connections/wires too much the joints would break off.

After putting each USB in, I had to bend and twist the wires so the Raspberry Pi and PiTFT still fit snugly in the case, with the wires bent around it.

I soldered the 3 green wires to the Vs, EN, and GND through-holes and connected them to the power switch (not shown). The USB cable soldered to the pi I plugged into the socket, and in the top right hand corner I used a multimeter to find the polarities of the Low Battery LED pads, and soldered one of the 3mm LEDs to that.

Under that swarm of wires I placed the LiPo battery and taped it to the bottom with electrical tape.

Soon after, all I had to do was plug in the LiPo to the Powerboost 1000c, put the bevels in place, and watch the magic happen (the tape is on the top because I haven’t decided on a good way to secure the bevel yet).

img_5227.jpg

img_5232.jpg

Viola!! My very own portable linux computer. SO EXCITED!!

And yes, that is Doctor Strange as my background. ๐Ÿ˜‰

I’m feeling very accomplished about this, and I hope this walk-through has entertained you or inspired you to make one of your own.
If you have any questions about things I did, don’t hesitate to contact me!

Until next time.

{thallia}

4x4x4 Rainbow LED Cube – Final product!

After connecting all the pins from the board into my Uno, all I had to do was plug in the power.

I preloaded a program onto the Uno off of the tutorial: http://www.makeuseof.com/tag/how-to-make-a-pulsating-arduino-led-cube-that-looks-like-it-came-from-the-future/

And this was the result!

I can adjust the speed if I so wish.
I’m hoping to see if I can hook this up to music and get it to dance to the sine waves like the laminar fountain, but we’ll see.

{thallia}