Author: ishanajay2012

  • How to disconnect WiFi devices on another network using the ESP8266

    There is a common WiFi attack that can disconnect any device on the network you are currently on. It also works on networks that you are not currently on.

    How it works

    There is a protocol in WPA2 that lets you disconnect a device safely from a network. However, these packets are not encrypted, so anyone with a WiFi-enabled device (like the ESP8266) can fake these packets.

    Installing the software

    First, go to the ESP8266 deauther page and download the latest release and download the file esp8266_deauther_[VERSION]_NODEMCU.bin.

    Next, download the ESP8266 Flasher and run the utility. Flash the binary file (the .bin you downloaded) at 0x00000. Click Flash and wait till it completes.

    Running attacks

    On a device, connect to the Wi-Fi network named pwned and enter the password deauther. Next, go to the IP address 192.168.4.1 and click I have read and understood the risks and choose a target network. Under the Attacks tab, begin the attack Deauth.

    A note on WPA3

    WPA3, which was passed as an official WiFi protocol, encrypts these packets so hackers cannot abuse them. However, some WiFi routers still use WPA2, so this attack will still work sometimes.

  • How to Install the Play Store on Windows 11

    You can sideload apps on Windows 11, but you are missing out on some key features by sideloading, like Google Play Services. With this tutorial, you will be able to run the Play Store directly on Windows, and you can install apps without sideloading.

    Step 1: Uninstall any existing WSA instances

    Below are the following steps:
    • Press Windows Key + I to open the settings menu
    • Click Apps
    • Click Installed Apps
    • Find Windows Subsystem For Android™, and click the three dots
    • Click Uninstall, and confirm the prompt

    Step 2: Enable Developer Options

    To do this,

    • Open Settings with the keyboard shortcut Windows Key + I
    • Click on Privacy and Security
    • Click For Developers under the Security section
    • Enable Developer Mode, and click on Yes when asked to confirm

    Step 3: Allow the Windows Hypervisor Platform to Run

    If you have installed WSA previously, or have the Virtual Machine Platform and the Windows Hypervisor Platform enabled already, you can feel free to skip this step. However, it is always best to make sure these necessary features are enabled. If you have no idea what I am talking about or have not installed WSA before, these steps are necessary:

    • Press Windows Key + S to open Search
    • Type “Turn Windows Features on or off” and click Enter
    • Look for Virtual Machine Platform and Windows Hypervisor Platform and enable them
    • Click OK and restart the machine when asked to.

    Step 4: Download a modified WSA Installer

    • First, go to the MagiskOnWSA GitHub repository. Create an account if you don’t already have one or log in to GitHub.

    Note:

    The current GitHub repsoitory (LPosed/MagiskOnWSA) has been disabled by GitHub due to violations of the terms of service. I will update this if the repository comes back online, but for now, the repository is offline. It is also highly unlikley that the repository will come back online, as it has been down for a couple months now. However, there are still some mirrors and unmodified copies of the original that are still up. Some are listed below:

    • Then, on the GitHub repository, click Fork and wait till you see the Forked From menu. This repository is somewhat large, so give it some time to fork.
    • Once on your newly forked repository, click the Actions tab.
    • Now, if you receive the Workflows aren’t being run on this forked repository prompt, click I understand my workflows, go ahead and enable them.
    • Now, with workflows enabled, look for the workflow Build WSA in the left-hand pane and click it. After that, click Run Workflow.
    • In the flyout menu that shows up, keep all settings set to default but Variants of GApps. Under Variants of GApps, select (or type in) pico. If you are typing, make sure that the text you are typing into the text field is exact.

    Note:

    You can select other variants if you know what you are doing.

    • Now, click Run Workflow. After that, you should see a message at the top that says Workflow run was successfully requested. Be patient with the workflow, it usually takes a couple minutes to complete.
    • Once the workflow completed, click the workflow name and scroll down to the Artifacts section.
    • You will see two links to download files. Click on the file name corresponding to your CPU version, (arm64 or x64) and download the file. It is quite large, so store it accordingly. The file may take a while to download.
    • Right-click the ZIP file and click Extract, and choose the directory of your choice.

    Step 5: Finishing Up

    • In thhe newly created directory, look for the Install.ps1 file and right-click on it.
    • Click Open with PowerShell.
    • Click Open if asked to confirm the action.
    • The script will show the Operation Completed Successfully message on execution.
    • Be patient while the script installs the final bits of WSA (Windows Subsystem for Android) and you will see a few installation notifications, and the script will exit after installing.
    • If prompted, click Allow Access so that Windows lets the Windows Subsytem for Android package on your network.
    • Click the start menu and type Windows Subsystem for Android. Open the application shown in search results.
    • Switch Developer Mode on if it is not already.
    • Click on Manage Developer Settings under the Developer Mode switch. This will restart WSA.
    • Now, when you open the Start Menu, you should see Play Store as one of the options. Open the app.
    • Allow the app through Windows Defender Firewall.
    • Now, you can open the Play Store just like any other app and sign in with your Google account. It will preform it’s usual synchronization, and then you can install Play Store apps on Windows 11.

    Note:

    If you can’t sign in, click Finish Setup in the system tray notification.

    Done!

  • Using the Raspberry Pi to Feed to FlightRadar24, FlightAware, and ADS-B Exchange

    Using the Raspberry Pi to Feed to FlightRadar24, FlightAware, and ADS-B Exchange

    In this post, I will be showing you how to start feeding flight data to three services: Flightradar24, ADS-B Exchange, and FlightAware. This post may be helpful to some of you who want to run your own flight feeder, and can’t tell which is a better service to feed to.

    The main benefit of running your own Raspberry Pi flight tracker is that you will get paid accounts for free. For example, you will get a free FlightAware enterprise account, a subscription valued at around $89.95 a month. FlightRadar24 will also give you a free business plan, which costs $49.99 a month. If you also want to support non-proprietary websites, you can also give flight data to ADS-B Exchange.

    What you will need (hardware)

    Below are the parts you will need:

    Raspberry Pi 3B (x1, required)

    The Raspberry Pi will be our microcontroller (This also works with other models, just not the Zero or the Pico; you can see FlightAware’s compatibility list here)

    ADS-B Dongle (x1, required)

    This will pick up ADS-B signals from nearby aircraft.

    MicroSD Card (at least 8GB, x1, required)

    The Raspberry Pi will be our microcontroller.

    Flashing our PiAware image

    To begin the installation, we will have to first start feeding to FlightAware. To begin, first, create an account at their website, or log in at their website.

    Now download the PiAware image (direct download for 7.2), and download Etcher. Then flash Etcher to your device using the PiAware ISO.

    Note that you must select the correct drive, as this will erase your drive.

    Configuring the ISO

    If you want to enable SSH on your PiAware, or you have a wireless network configuration that you want to set (this will be typically everyone, unless you are using an ethernet cable on your Raspberry Pi), you must follow the below steps to configure the new operating system to use your configurations. You can refer to the configurations at FlightAware’s Website, or you could not set a default configuration, and once the PiAware has booted up, configure it using Bluetooth.

    Booting it up

    Now, you can put it all together! Connect your ADS-B antenna to your Raspberry Pi via USB, and then put the SD card through the back. Then, plug in the HDMI cable (and ethernet if you are going to be using it), and power it on.

    Now, once the Raspberry Pi has booted up, you should see a screen showing the PiAware Status. If you did this correctly, it should be connected. You will also need to connect a keyboard if you do not know your PiAware’s IP address. If it asks you for credentials, the default is pi for username, and raspberry for password.

    Setting up the FlightAware feeder

    Now we get to the fun part! Now, we set up the feeders. Let’s start off with the FlightAware feeder. Since we flashed the custom ISO file, FlightAware is going to be installed, just not set linked to an account. Create a basic plan FlightAware account at their website if you don’t already have one, and claim your PiAware. Once that is set up, make sure you are connected to the same network as your PiAware. It will come in handy for later. Once you do that, make sure you are still on the status page on your PiAware, click Alt+F2 (or whatever key it says to press to open the terminal and run commands). If it asks you for credentials, the default is pi for username, and raspberry for the password (unless it is set otherwise, of course). Now run the following command:

    BASH
    
    hostname -I

    This should return your Pi’s IP address. Now, on another device, navigate to your IP address on the SkyAware page. For example, if my Pi’s IP address is 192.168.1.1, I will navigate to the following website:

    URL
    
    http://192.168.1.1/skyaware

    After that, you should see a map with all the aircraft you are tracking. You have successfully set up FlightAware! After some time, your basic account will be upgraded, and you can view your ADS-B statistics.

    Setting up FlightRadar24

    Now, open the terminal and run the following command:

    BASH
    
    sudo bash -c "$(wget -O - http://repo.feed.flightradar24.com/install_fr24_rpi.sh)"

    You will then be asked some questions about antenna position, fr24 sharing key, and other things.

    Now, we need to configure FlightRadar24. To begin, sign up for an account at their official website. Note that all you need to do is sign up for a free account and do not select any paid plans. This is because your account will automatically be upgraded at the end of this tutorial.

    Run the following command to enter configuration:

    BASH
    
    sudo fr24feed --signup

    You will be asked questions about you and the antenna that you are using. Answer the questions similar to the ones below:

    • Email Address: Enter the same email address you used to sign up for FlightRadar24. This is the same email address that your sharing key will be sent to, and the same email address that your account on will be upgraded.
    • FR24 Sharing key: If you have never set up a feeder or have never got a sharing key from FlightRadar24, leave this blank. If not, enter your FlightRadar24 sharing key.
    • Participating in MLAT Calculations: Answer yes, unless you know you don’t want it or need it.
    • Autoconfiguration for dump1090 (if asked): Yes
    • Latitude & Longitude: Use a website like latlong.net to find your latitude and longitude. It is best to be as accurate as possible. Enter this question in the form of XX.XXXX and XX.XXXX (leave out any extra numbers).
    • Altitude: This is your altitude from sea level. You can use whatismyelevation.com to find your altitude.
    • Receiver Selection: If you are using a DVB-T (the type I put in the parts list) stick then I strongly recommend option 1. If you encounter an error regarding dump1090 in this tutorial, restart the tutorial and click option 4. If you do not have a DVB-T stick, check out your other options.
    • Dump1090 Arguments (if asked): Leave this blank and hit enter.
    • Raw Data Feed: No, unless you know what you are doing.
    • Basestation Data feed: No unless you know what you are doing.
    • Logfile Mode: 48-hour, 24 rotation.
    • Logfile Path: This will be the path that the log file is saved to. If you want to use a custom path for logs, put it here. If not, stick with the default and hit enter.

    FlightRadar24’s configuration should return that everything is correctly set up. The program should also give you a sharing key. Save this key as you may need it later in the future.

    To begin feeding ADS-B data to FlightRadar24, enter the command below. Note that MLAT or general feeding might take some time to show up. For me, it took 30 minutes before the feeder was actively sending data to FlightRadar24:

    BASH
    
    sudo systemctl restart fr24feed

    You can go to the data page and view your feeder statistics. If you want to access the web UI for FlightRadar24, then go to your Raspberry Pi’s IP address (remember, you can access it with sudo hostname -I), and access it via a web browser on port 8754, unless set otherwise. For example, my Raspberry Pi’s IP address is 192.168.1.252, so I access it by using http://192.168.1.252:8754.

    Also, it is important to note that it may take some time for the receiver to start working and sending data. For me, it took 30 minutes before flight data was sent to the services I was feeding to.

    Setting up MLAT for FlightAware

    If you want to set up MLAT configurations on FlightAware (we highly recommend doing so, it can increase the amount of positions seen), then follow our steps.

    First, go to your FlightAware data sharing page and clcik the gear icon next to the nearest airport, labeled in orange.

    Then, enable MLAT and Mode S Alliteration. Put in the same details as you did for FlightRadar24, or new details if you have to.

    Setting up ADS-B Exchange

    First, we need to download ADS-B Exchange. You can do that with the following command:

    BASH
    
    sudo bash -c "$(wget -nv -O - https://raw.githubusercontent.com/adsbxchange/adsb-exchange/master/install.sh)"
    

    You will be asked a couple questions. For the first one, type in a random username, but note that this username will be public. Next, enter the details it asks for, and it will begin configuring. Note that this may take a while.

    Next, run the following command:

    BASH
    
    sudo bash /usr/local/share/adsbexchange/git/install-or-update-interface.sh

    The script should output a sharing key. You can use this to view your feeder statistics at the official website of ADS-B Exchange. You should also be able to access your web interface on the adsbx page. This will be your Raspberry Pi’s IP address, with /adsbx at the end. For me, the URL was http://192.168.1.252/adsbx.

    Aftermath

    PiAware status (FlightAware)
    SkyAware Map (FlightAware)
    Data sharing Page (FlightAware)
    Flight map (tar1090) (ADS-B Exchange)
    Status Page (FlightRadar24)
    Data sharing page (FlightRadar24)
  • Tensors Dimensions and Basics in Python Artificial Intelligence and Machine Learning

    In PyTorch and TensorFlow, Tensors are a very popular way of storing large amounts of data in artificial intelligence projects. Here, I will show you what they are, and how they work.

    What makes a Tensor?

    Tensors are made up of Scalars, Vectors, and Matrixes. Scalars are single numbers. Vectors are a line of numbers, and Matrixes are, as the name suggests, Matrixes, or tables, of numbers.

    Here is an example: If you are making an image, you can think of Matrixes as images, Scalars as pixels or dots, and Vectors like rows. You can think of Tensors as a Matrix that contains Matrixes.

    Yellow: Main tensor

    Red: Matrix 1

    Cyan/Light Blue: Matrix 2

    Orange: Vectors

    Green: Scalars

    Matrix dimension

    Matrixes are tables of numbers, so the number of rows and columns in the matrix is the matrix dimension. Below is an example.

    12
    34

    There are two rows and two columns in this table of numbers or matrix, so the dimensions of this matrix are two by two. Below is another example.

    1234
    1234
    1234
    1234

    What I showed you had four rows and columns, so the matrix above is a four-by-four matrix.

    Tensor Dimension

    Tensor dimensions are made up of three things. Earlier in this post, I mentioned how a tensor is a matrix containing matrixes. The first dimension of a tensor is how many matrixes the tensor should have in it. The next two dimensions are the dimensions you want each matrix to have. For example,

    1234
    5678
    9101112
    13141516

    would be a 4×4 matrix. If you wanted four four-by-four matrixes, you would need to make the first dimension (the number of matrixes to be in the tensor, which, as I said, is a matrix full of matrixes) four. Then, you would want 4×4 matrixes, so you would input the next two dimensions as 4 and 4 for a 4×4 tensor.

    Tips

    • If you do not input your first dimension (the number of matrixes in the tensor) into a tensor, the number defaults to 1.
    • Tensors are useful for storing mass amounts of data.
    • One of the easiest ways to make a tensor with custom values would be to have a loop running into every scalar in the tensor, thus making every scalar something you choose.
    • Tensors, when stored, are stored unevaluated. This means that your actual data, typically the data you would be storing in a tensor would be numbers, is not actually stored raw, but rather compressed, which makes tensor storage much easier for the machine’s memory, since the data is significantly less complicated. This is what makes tensors so popular for the storage of mass data. If you want to see the actual, uncompressed data of a tensor, you must evaluate it. You can do this with a simple function in both PyTorch and TensorFlow.
  • Everything to know about “Follina” (CVE-2022-30190)

    “Follina”, or CVE-2022-30190 is a widely used exploit that allows an attacker to remotely execute Powershell code on Windows machines from a Microsoft Word document or a URL.

    What it does

    Follina can do anything the attacker desires. Follina is a remote-code execution scheme, which means that a hacker can run any code the hacker wants on your machine without your knowledge. Some examples include lateral movement, privilege escalation, and the ability to steal browser credentials.

    How it works

    Follina takes advantage of URL protocols. URL protocols are used to run applications from a URL. Many people let this happen, mainly because URL protocols are not supposed to invoke code from applications. For example, if you are on a Windows machine, and you type “ms-calculator://” into the address bar, Windows should launch the calculator. However, the specific URL protocol Follina takes advantage of is “ms-msdt://”. This will launch the Microsoft Support Diagnostics Tool, which is mainly used by support professionals to gain information about your system. If you put some special parameters into the URL though, you can trick the program into running Powershell code, and sending the results to the hacker.

    How it was discovered

    The thing about Follina is that it was first discovered early-to-mid April of 2022 by someone who goes by the name of “crazyman” as part of the Shadow Chaser Group. However, Microsoft dismissed the threat, stating that it is not a security issue.

    The support representative stated that his sample did not work at his lab. MSDT requires a password on startup, but the original script had enough junk and padding to make this file over 4096 bytes, and according to my tests and speculations, MSDT will only open if the exploiting file is over 4096 bytes. Also, this can be exploited through Rich Text Documents and URLs or URL shortcuts, not just Word documents. Another reason that this is a dangerous threat is that, when saved as a Rich Text file, simply navigating to it and opening it up in the preview pane in File Explorer could trigger the execution, meaning that you don’t even have to open the file for the code to be invoked.

    However, this file was only brought to the community’s attention when a Twitter user by the name of “nao_sec”, was looking for documents on VirusTotal using an older exploit, CVE-2021-40444, found this document and alerted the community about it.

    How to protect yourself

    Because Follina is a zero-day exploit, there is no guaranteed patch. There is one solution that Microsoft acknowledged. The solution disables the “ms-msdt://” URL protocol.

  • How to make permanent bash aliases and bash functions

    In the last post, I covered how to make bash aliases. However, creating bash aliases with the alias command only lets you create bash aliases for the current session. For example, if I were to use alias hi="echo hi" to make a bash alias that connects hi with the command echo hi, and then exited the terminal session, all the bash aliases would reset. However, there is a way to make them permanent.

    Creating Permanent Bash aliases

    To make Bash aliases permanent, you will need to add lines to the ~/.bash_profile or ~/.bashrc file. Once you find out that file, open it with the text editor of your choice. I prefer nano.

    Make sure to run the below command after you are done modifying those files:

    BASH SHELL
    source ~/.bash_profile

    The below commands are how you get into the file.

    BASH SHELL
    cd ~
    nano .bashrc

    Then add your aliases.

    BASH CONFIGURATION
    # Aliases
    # alias alias_name="command_to_run"
    
    
    # If you are new to the shell, note that the Linux system ignores lines that start with '#' so this line does not mean anything to Linux
    
    # Long format list
    alias ll="ls -la"
    
    # Print my public IP
    alias myip="curl ipinfo.io/ip"
    
    # That 'hi' example from earlier
    alias hi="echo hi"

    Now when you reboot your Linux system, the Bash aliases should still work.

    Bash aliases with command arguments (Bash functions)

    Sometimes you may need to create a Bash alias that will change depending on certain values or will accept arguments. The syntax for Bash functions is relatively easy. They can be declared in two separate formats. It is preferred to declare functions using the ~/.bashrc file.

    TIP: If you want your .bashrc file to be more modular, you can store your aliases in a separate folder. Some distributions of Linux like Ubuntu or Debian include a separate .bash_aliases file.

    The syntax is below. Way 1 is the preferred way and the most used one.

    Way 1 (Multi-Line):

    BASH CONFIGURATION
    function_name () {
      commandsToRun
    }

    Way 1 (Single-Line):

    BASH CONFIGURATION
    function_name () { commandsToRun; }

    Way 2 uses the keyword of function, and then the function name, and after that the commands to run. The code below demonstrates way 2 (multi-line):

    BASH CONFIGURATION
    function function_name {
      commandsToRun
    }
    

    Way 2 (Single-Line):

    BASH CONFIGURATION
    function function_name { commandsToRun; }

    A few things that are nice to know:

    • The commands that the function will run are between the curly braces ({}). This is called the body of the function. The curly braces must be separated from the body by newlines or spaces. In this case, function A {commandsToRun;} or A () {commandsToRun;} will not work, but something like function A { commandsToRun; } or A () { commandsToRun; } which has spaces separating the body of the function from the function data will.
    • Simply defining a function will not execute it. If you want to invoke or execute a bash function simply use the name of the function. The body of the function is executed when you invoke it in the shell script.
    • You must define the function before calling or executing it.

    You can pass any number of arguments in a function. If you want to call a Bash function right after the function’s name, separated by a space. The passed parameters can be referenced with $1, $2, $3, $4, etc., corresponding to the position of the argument after the name of the function when it is executed. Below is a simple bash function that will create a directory and then navigate into it:

    BASH/SH
    mkcd () {
      mkdir -p -- "$1" && cd -p -- "$1"
    }

    Same as aliases, make sure to add the Bash functions in the ~/.bashrc file and run source ~/.bash_profile to make the changes take effect.

    Now instead of having to make a directory using mkdir and then move into that directory using cd, you can simply use our mkcd function:

    BASH SHELL
    mkcd testDirectory

    A few things that you need to know:

    • The -- makes sure that Linux does not get confused and parse the folder name as an argument. If you have a folder that starts with -, Linux might parse it as an argument.
    • The && ensures that the second command runs only if the first one is successful.

    Final Note

    By now you should have a good understanding of how Bash aliases and functions work. This should help you be more productive on the command line.

    If you have any questions or feedback, feel free to leave a comment on this post.

  • How to Create Bash Aliases in Linux, and How They Work

    If you are like me, you will often find yourself typing long, bulky, and hard-to-remember commands in the Linux terminal, and if not, I will almost always find myself searching the bash history for a long command I typed earlier. If you are also like me, this is where bash aliases come in handy. Bash aliases are like shortcuts, short, quick replacements for long, bulky commands. For example, you can use rmopwrt instead of opkg remove --force-remove --force-removal-of-dependent-packages ppp ppp-mod-pppoe odhcpd-ipv6only dnsmasq hostapd-common luci luci-ssl-openssl luci-base lua luci-app-firewall luci-lib-ip luci-lib-jsonc luci-lib-nixio luci-proto-ipv6 luci-proto-ppp luci-theme-bootstrap uhttpd uhttpd-mod-ubus. In this post, I will show you how to create bash aliases in Linux, so you can save time on the command line, and be more productive.

    Creating Bash Aliases

    Creating bash aliases is very easy and straightforward. The basic command is as follows:

    BASH SHELL
    
    alias whatever_you_want_your_alias_to_be_called="command_to_run"

    However, like always, make sure not to use spaces in the name, else Linux will think it is a command argument, and the alias command does not take any. When you create an alias, you type “alias”, followed by your alias name, an equal sign without spaces, and then, without spaces, in quotes, what command the alias should run. In the case above, running whatever_you_want_your_alias_to_be_called will do the same thing as running command_to_run.

    Let us try another example.

    BASH SHELL
    
    alias myip="hostname -I"

    When you run myip, you will get the same output as running hostname -I.

    Done!

  • How to turn your Raspberry Pi into a WiFi router using OpenWrt

    How to turn your Raspberry Pi into a WiFi router using OpenWrt

    LightDarkDarkDark

    In this guide, I will be turning a Raspberry Pi into an OpenWrt router. This is good for travel, and it can connect to VPN servers to give you secure VPN internet.

    What will you need?

    Here is a list of items you will need:

    Step 1: Bake the Pi

    First, we need to install OpenWrt on the board. To do that, put the MicroSD card into the MicroSD card reader, then plug the MicroSD card reader into the computer.

    Now install the Raspberry Pi Imager.

    Once that is done, download the proper firmware from this site. Then, once you have the Raspberry Pi Imager open, select, click “Choose OS”. Then scroll down and click “Use Custom”, then select the location of the firmware that you downloaded from the OpenWrt Wiki.

    Click “Select Drive”, then click the drive of the SD card reader.

    Step 2: Connect to OpenWrt via SSH

    Now, plug the ethernet cable into your Raspberry Pi, then plug the other end into your computer. Open Command Prompt, then run:

    BATCH
    
    ssh root@192.168.1.1

    On the fingerprint prompt, type “yes”.

    Step 3: Setting a password

    When we used SSH to log in to the OpenWrt session, notice that it did not prompt us for a password. Super insecure. To set one, run the command. This is also how you change the password on any Linux device:

    ASH SHELL
    
    passwd root

    Follow the prompts.

    Step 4: Backing up all of the config files

    Run all these commands, in order:

    ASH SHELL
    
    cd /etc/config/
    cp firewall firewall.bk
    cp wireless wireless.bk
    cp dhcp dhcp.bk
    cp network network.bk

    Step 5: Netwok Configuration Settings

    Run these commands. I hooked mine up to the LAN interface, if you want to use Wi-Fi, follow the official documentation. These will configure OpenWrt to connect to your network.

    ASH SHELL
    
    uci set network.lan.ipaddr=192.168.2.2
    uci set network.lan.gateway=192.168.2.1
    uci set network.lan.dns=192.168.2.1
    
    uci commit
    service network restart

    Step 6: Partitioning

    Create a partition to store data. We will install fdisk and use it:

    opkg update
    opkg install fdisk
    fdisk /dev/mmcblk0

    To create two partitions (one for /home and one for /srv), use the following fdisk commands.

    • p to print the current partition table.
    • n then e to create an extended partition.
    • n then l to create the first partition. When asked for the last sector, type +2G to make it 2GB large.
    • n then l to create the second partition. When asked for the last sector, leave empty to fill the remaining space.
    • w to write the partition table.

    And reboot your Raspberry Pi!

    Step 7: Creating a filesystem on our partitions

    Run these commands:

    ASH SHELL
    
    mkfs.ext4 /dev/mmcblk0p5
    mkfs.ext4 /dev/mmcblk0p6

    Now we can mount the first partition at /home and the second at /srv. Both are on a flash SD card, the noatime flag is important.

    ASH SHELL
    
    opkg update
    opkg install block-mount
    block detect | uci import fstab
    uci set fstab.@mount[2].target=/home
    uci set fstab.@mount[2].enabled=1
    uci set fstab.@mount[2].options=noatime
    uci set fstab.@mount[3].target=/srv
    uci set fstab.@mount[3].enabled=1
    uci set fstab.@mount[3].options=noatime
    uci commit

    Create the srv mount point, as the other one already exists.

    ASH SHELL
    
    mkdir -p /srv

    Mount both partitions.

    ASH SHELL
    
    block mount

    Step 8: Set the hostname

    ASH SHELL
    
    uci set system.@system[0].hostname='thetechmaker-good.hi.testing'
    uci commit

    Step 9: Remove unused packages

    OpenWrt was originally a Linux distribution for routers, so it might come with useless networking software you’ve never heard of. You can remove this with the following commands:

    ASH SHELL
    
    opkg remove --force-remove --force-removal-of-dependent-packages ppp ppp-mod-pppoe odhcpd-ipv6only dnsmasq hostapd-common luci luci-ssl-openssl luci-base lua luci-app-firewall luci-lib-ip luci-lib-jsonc luci-lib-nixio luci-proto-ipv6 luci-proto-ppp luci-theme-bootstrap uhttpd uhttpd-mod-ubus
    

    Step 10: Done!

  • How to make an IoT fire alarm.

    If you are looking for a nice fire solution in a place where false alarms happen a lot, this is by far the cheapest, best solution I know.

    What you will need – Hardware

    What you will need – Software

    How to create – Step 1: Setting up Blynk

    First, make sure you have the app on your phone.

    Now create an account or log in.

    Click “New Project”.

    Give an appropriate project name. I thought that the name “Fire Sensor” would be reasonable.

    Choose the device name of “ESP8266” or, more preferably, “NodeMCU”.

    An auth token will be sent to your email. Keep this safe, you are going to need it later on.

    Drag and drop the “Push Notification” widget and press the play icon at the far top, far right corner.

    How to create – Step 2: Getting the hardware right

    Here are the schematics:

    • AO on the flame sensor should not be connected to anything
    • G or GND on the flame sensor should go to GND on the ESP8266
    • + or VCC on the flame sensor should go to VIN on the ESP8266
    • DO on the flame sensor should go to D1 on the ESP8266

    How to create – Step 3: Getting the software right

    First, install the library from this URL:

    https://github.com/blynkkk/blynk-library

    Now, in the IDE, go to File > Preferences.

    When it says “Additional Board Manager URL’s”, paste in this:

    URL LIST
    
    https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json

    Now go to Boards > Board Manager.

    Search “ESP8266” and install “esp8266 by ESP8266 Community”.

    Now go to Boards > NodeMCU 1.0 (ESP-12E Module) or more preferably, Boards > Generic ESP8266 Module.

    Upload the following code, replacing certain things:

    C#, C++, C
    
    #define BLYNK_PRINT Serial
    #include 
    #include  
    BlynkTimer timer;
    char auth[] = "No!"; //Replace with auth code sent via Email
    char ssid[] = "hacked"; //Replace with wifi name
    char pass[] = "123456789"; //Replace with Wifi Password
    int flag=0;
    void notifyOnFire()
    {
    int isButtonPressed = digitalRead(D1); // falme sensor connected D1 pin
    if (isButtonPressed==1 && flag==0) 
    {
    Serial.println("Fire DETECTED");
    Blynk.notify("Alert : Fire detected");
    flag=1;
    }
    else if (isButtonPressed==0)
    {
    flag=0;
    }
    }
    void setup()
    {
    Serial.begin(9600);
    Blynk.begin(auth, ssid, pass);
    pinMode(D1,INPUT_PULLUP);
    timer.setInterval(1000L,notifyOnFire); 
    }
    void loop()
    {
    Blynk.run();
    timer.run();
    }

    DONE!

  • How to use the DHT11/22 sensor to log data to Google Sheets

    By this time, you’d probably want a temperature sensor in the house – one less than $25. If you have one, you are probably wanting a better one. Here is an easy solution to this problem.

    Things that you’ll need – Hardware

    Things that you’ll need – Software

    Creating And Deploying The Script

    Create a new spreadsheet as shown below:

    Once you have got that down go to Tools > Script Editor. We’ll continue from there.

    Name the sheet below TempSheet

    In the script editor, copy and paste the code given here. Edit the script ID in the code. The script ID is found in the place where “vbn” is in the given URL:

    URL
    
    https://docs.google.com/spreadsheets/d/vbn/edit#gid=0

    Now go to Publish > Deploy as a web app. The “Project version” will be “New”. Select “your email id” in the “Execute the app as” field. Choose “Anyone, even anonymous” in the “Who has access to the app” field. And then click on “Deploy”. Note that When republishing please select the latest version and then Deploy again. Type “New Script Created” in the “Project Version” field.

    You will have to give Google permission to deploy it as a web app. Just click on “Review Permissions”. Then choose your Email ID here using which you have created the spreadsheet.

    Click on “Advanced”.

    And then click on Go to your_script_name(unsafe). Here in my case, it is “TempLog_Script”.

    Click on “Allow” and this will give permission to deploy it as a web app.

    Now you can see the new screen with a given link and named “Current web app URL”. This URL contains Google Script ID. Just copy the URL and save it somewhere.

    Testing the DHT11/22

    Use the given circuit diagram and code:

    Diagram:

    Code:

    C#, C++, C
    
    #include "DHT.h"
    
    #define dht_apin A0
    
    DHT dht;
    
    #define DHTTYPE DHT22 //Change this to any type of DHT Sensor you're Using!
    
    DHT(dht_apin, DHTTYPE);
    
    void setup() {
    
    // put your setup code here, to run once:
    
    Serial.begin(9600); //Starts serial
    
    delay(5000); //Waits before reading from sensor
    
    Serial.println("DHT22 Temp. And Humi. Test"); //Prints the intro
    
    }
    
    void loop() {
    
    // put your main code here, to run repeatedly:
    
    dht.read11(dht_apin); //Reads from the sensor
    
    Serial.println("Humi. ---------- "); //Prints humidity
    
    Serial.print(DHT.humidity); //Prints humidity
    
    Serial.print("% "); //Marks the humidity as %
    
    Serial.print("Temp. ------------ "); //Prints temperature
    
    Serial.print(DHT.temperature); //Prints temperature
    
    Serial.print("℃") //Marks the temperature unit
    
    delay(2000); //Waits 2 seconds before doing the loop again fastest is once evrey 2 seconds
    
    } //end loop

    It should be printing the temperature and humidity. If it is not, try running this code at rate 9600 that will print “Hello!” every second to see if you are getting any serial communication at all:

    C#, C++, C
    
    #define one_second 1000
    
    #define the_word_hello "Hello!"
    
    void setup() {
    
    // put your setup code here, to run once:
    
    Serial.begin(9600);
    
    delay(5000);
    
    }
    
    void loop() {
    
    // put your main code here, to run repeatedly:
    
    Serial.print(the_word_hello);
    
    delay(one_second);
    
    }

    If it is all working, we can move on.

    Sign up for our newsletter!

    Schematics

    As you can see in the picture:

    • D4 pin on the NODEMCU > DATA pin on the DHT11/22
    • GND pin on the NODEMCU > GND pin on the DHT11/22
    • 5V pin on the NODEMCU > VCC pin on the DHT11/22

    Using the Arduino IDE, upload the following code:

    Programming language(s) C#, C++, C: ***{Code starts after this line}***
    
    #include <ESP8266WiFi.h>
    #include "HTTPSRedirect.h"
    #include "DebugMacros.h"
    #include <DHT.h>
    
    #define DHTPIN D4                                                           // what digital pin we're connected to
    #define DHTTYPE DHT11                                                       // select dht type as DHT 11 or DHT22
    DHT dht(DHTPIN, DHTTYPE);
    
    float h;
    float t;
    String sheetHumid = "";
    String sheetTemp = "";
    
    const char* ssid = "";                //replace with our wifi ssid
    const char* password = "";         //replace with your wifi password
    
    const char* host = "script.google.com";
    const char *GScriptId = "AKfycbxy9wAZKoPIpPq5AvqYTFFn5kkqK_-avacf2NU_w7ycoEtlkuNt"; // Replace with your own google script id
    const int httpsPort = 443; //the https port is same
    
    // echo | openssl s_client -connect script.google.com:443 |& openssl x509 -fingerprint -noout
    const char* fingerprint = "";
    
    //const uint8_t fingerprint[20] = {};
    
    String url = String("/macros/s/") + GScriptId + "/exec?value=Temperature";  // Write Teperature to Google Spreadsheet at cell A1
    // Fetch Google Calendar events for 1 week ahead
    String url2 = String("/macros/s/") + GScriptId + "/exec?cal";  // Write to Cell A continuosly
    
    //replace with sheet name not with spreadsheet file name taken from google
    String payload_base =  "{\"command\": \"appendRow\", \
                        \"sheet_name\": \"TempSheet\", \
                           \"values\": ";
    String payload = "";
    
    HTTPSRedirect* client = nullptr;
    
    // used to store the values of free stack and heap before the HTTPSRedirect object is instantiated
    // so that they can be written to Google sheets upon instantiation
    
    void setup() {
      delay(1000);
      Serial.begin(115200);
      dht.begin();     //initialise DHT11
    
      Serial.println();
      Serial.print("Connecting to wifi: ");
      Serial.println(ssid);
      
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("WiFi connected");
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());
    
      // Use HTTPSRedirect class to create a new TLS connection
      client = new HTTPSRedirect(httpsPort);
      client->setInsecure();
      client->setPrintResponseBody(true);
      client->setContentTypeHeader("application/json");
      Serial.print("Connecting to ");
      Serial.println(host);          //try to connect with "script.google.com"
    
      // Try to connect for a maximum of 5 times then exit
      bool flag = false;
      for (int i = 0; i < 5; i++) {
        int retval = client->connect(host, httpsPort);
        if (retval == 1) {
          flag = true;
          break;
        }
        else
          Serial.println("Connection failed. Retrying...");
      }
    
      if (!flag) {
        Serial.print("Could not connect to server: ");
        Serial.println(host);
        Serial.println("Exiting...");
        return;
      }
    // Finish setup() function in 1s since it will fire watchdog timer and will reset the chip.
    //So avoid too many requests in setup()
    
      Serial.println("\nWrite into cell 'A1'");
      Serial.println("------>");
      // fetch spreadsheet data
      client->GET(url, host);
      
      Serial.println("\nGET: Fetch Google Calendar Data:");
      Serial.println("------>");
      // fetch spreadsheet data
      client->GET(url2, host);
    
     Serial.println("\nStart Sending Sensor Data to Google Spreadsheet");
    
      
      // delete HTTPSRedirect object
      delete client;
      client = nullptr;
    }
    
    void loop() {
    
      h = dht.readHumidity();                                              // Reading temperature or humidity takes about 250 milliseconds!
      t = dht.readTemperature();                                           // Read temperature as Celsius (the default)
      if (isnan(h) || isnan(t)) {                                                // Check if any reads failed and exit early (to try again).
        Serial.println(F("Failed to read from DHT sensor!"));
        return;
      }
      Serial.print("Humidity: ");  Serial.print(h);
      sheetHumid = String(h) + String("%");                                         //convert integer humidity to string humidity
      Serial.print("%  Temperature: ");  Serial.print(t);  Serial.println("°C ");
      sheetTemp = String(t) + String("°C");
    
      static int error_count = 0;
      static int connect_count = 0;
      const unsigned int MAX_CONNECT = 20;
      static bool flag = false;
    
      payload = payload_base + "\"" + sheetTemp + "," + sheetHumid + "\"}";
    
      if (!flag) {
        client = new HTTPSRedirect(httpsPort);
        client->setInsecure();
        flag = true;
        client->setPrintResponseBody(true);
        client->setContentTypeHeader("application/json");
      }
    
      if (client != nullptr) {
        if (!client->connected()) {
          client->connect(host, httpsPort);
          client->POST(url2, host, payload, false);
          Serial.print("Sent : ");  Serial.println("Temp and Humid");
        }
      }
      else {
        DPRINTLN("Error creating client object!");
        error_count = 5;
      }
    
      if (connect_count > MAX_CONNECT) {
        connect_count = 0;
        flag = false;
        delete client;
        return;
      }
    
    //  Serial.println("GET Data from cell 'A1':");
    //  if (client->GET(url3, host)) {
    //    ++connect_count;
    //  }
    //  else {
    //    ++error_count;
    //    DPRINT("Error-count while connecting: ");
    //    DPRINTLN(error_count);
    //  }
    
      Serial.println("POST or SEND Sensor data to Google Spreadsheet:");
      if (client->POST(url2, host, payload)) {
        ;
      }
      else {
        ++error_count;
        DPRINT("Error-count while connecting: ");
        DPRINTLN(error_count);
      }
    
      if (error_count > 3) {
        Serial.println("Halting processor...");
        delete client;
        client = nullptr;
        Serial.printf("Final free heap: %u\n", ESP.getFreeHeap());
        Serial.printf("Final stack: %u\n", ESP.getFreeContStack());
        Serial.flush();
        ESP.deepSleep(0);
      }
      
      delay(3000);    // keep delay of minimum 2 seconds as dht allow reading after 2 seconds interval and also for google sheet
    }