Fix WiFi LG G5 misc partition

yes, that command you listed wipes the misc partition. It should be avoided when possible.. instead.. only wiping the things to stop getting stuck in TWRP etc. Many suggest the quick and easy “wipe the entire thing” method… but you can now see some of the results from doing that. Since the G2 and G3 days I’ve been suggesting otherwise –…g-ota-t2907508

Command to safely get out of stuck TWRP would need to be updated for the G5:
dd if=/dev/zero of=/dev/block/bootdevice/by-name/misc bs=256 count=1 conv=notrunc

that would help some people stuck in TWRP (wont help those stuck in download mode.. they should just successfully flash a TOT/KDZ to stop phone from booting into download mode). And it may not work in every instance but should work in many.

As for “why is it wiping misc again?”…
it’s not. you placed a file in /data/ to fix the issue.. then you are wiping /data/. why would the fix stay? 
if you want a perm fix, fix misc and don’t bother with your temp fix in /data/. Or perhaps update you’re OP and include both (if my fix works.. but I believe it should) just so people have options.

Here’s a 10-step MAC Fix (assuming you aren’t using the “temp” fix in /data/)

1. backup/dump your misc partition:
dd if=/dev/block/bootdevice/by-name/misc of=/sdcard/misc-dump.img
or if in TWRP with encrypted /data use: dd if=/dev/block/bootdevice/by-name/misc of=/tmp/misc-dump.img to dump to the /tmp/ directory.

2. pull misc-dump.img from phone onto computer.
adb pull /sdcard/misc-dump.img
or adb pull /tmp/misc-dump.img

3. On computer, open up misc-dump.img in a hex editor. HxD is a decent free hex editor for Windows. Or use whatever.. hex editor is hex editor ( I use 010 Editor).

4. After opening the misc-dump.img in the hex editor you’ll see the file in raw hex. Scroll down to offset 6000 for the Wifi MAC.
As seen in the picture below, the Wifi MAC is @ 6000h and is currently DE:AD:BE:EF:FE:ED, you will edit that section with your original MAC address instead (or current mac address you want to stick).

5. Now scroll down to offset 8000 for the Wifi MAC.
As seen in the picture below, the BT MAC is @ 8000h and is currently DE:AD:BE:EF:CA:FE, you will edit that section with your original MAC address instead (or current mac address you want to stick).

6. Save the edits made to the misc-dump.img. To be proper, select “Safe As..” instead of save and name the new file: misc-fixed.img

7. Push the fixed misc partition to your phone:
adb push /sdcard/misc-fixed.img
or… adb push /tmp/misc-fixed.img

8. Flash the misc-fixed.img on your phone to your misc partition:
dd if=/sdcard/misc-fixed.img of=/dev/block/bootdevice/by-name/misc
or.. dd if=/tmp/misc-fixed.img of=/dev/block/bootdevice/by-name/misc

9. Reboot phone, or boot into Android if in TWRP. Wifi/BT MAC should now be fixed.

10. Save misc partitions just in case. Ideally you want an untouched misc partition before messing with anything on your phone.. sort of like backing up your EFS first. But worst case.. you can use the steps above to fix Wifi/BT MAC address issues.

Python Daemon

Here is what I have, that works for me. It also has a sysv init script. Repo is at GitHub, and I also have a brief blog post with links to other possible solutions I found.

There can only be one daemon process running: that is managed by the PID lock file, like most other Linux daemons. To stop it, do

kill `cat /var/run/`

To see if it is running:

ps -elf | grep `cat /var/run/`

Using the pidfile submodule, the PID file is managed automatically. When the daemon is stopped, the pidfile is cleared up. Please see the linked GitHub repo for the init script.

Here’s the Python daemon code:

#!/usr/bin/env python3.5
import sys
import os
import time
import argparse
import logging
import daemon
from daemon import pidfile

debug_p = False

def do_something(logf):
    ### This does the "work" of the daemon

    logger = logging.getLogger('eg_daemon')

    fh = logging.FileHandler(logf)

    formatstr = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    formatter = logging.Formatter(formatstr)



    while True:
        logger.debug("this is a DEBUG message")"this is an INFO message")
        logger.error("this is an ERROR message")

def start_daemon(pidf, logf):
    ### This launches the daemon in its context

    ### XXX pidfile is a context
    with daemon.DaemonContext(
        ) as context:

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Example daemon in Python")
    parser.add_argument('-p', '--pid-file', default='/var/run/')
    parser.add_argument('-l', '--log-file', default='/var/log/eg_daemon.log')

    args = parser.parse_args()

    start_daemon(pidf=args.pid_file, logf=args.log_file)

For completeness’ sake, here is the init script. Note that “kill” is really just a method for sending a POSIX signal — see man page for signal(7) for an overview. The python-daemon context will catch the signal, terminate the process cleanly closing file descriptors, and delete the PID file automatically. So, it really is a clean termination.

You can write your code to catch SIGUSR1 or something similar, in order to do a reload of the daemon config. There is no advantage to writing Python stop the daemon.

# eg_daemon      Startup script for eg_daemon
# chkconfig: - 87 12
# description: eg_daemon is a dummy Python-based daemon
# config: /etc/eg_daemon/eg_daemon.conf
# config: /etc/sysconfig/eg_daemon
# pidfile: /var/run/
# Provides: eg_daemon
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Short-Description: start and stop eg_daemon server
# Description: eg_daemon is a dummy Python-based daemon

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/eg_daemon ]; then
        . /etc/sysconfig/eg_daemon



start() {
        echo -n $"Starting $prog: "

        if [[ -f ${pidfile} ]] ; then
            pid=$( cat $pidfile  )
            isrunning=$( ps -elf | grep  $pid | grep $prog | grep -v grep )

            if [[ -n ${isrunning} ]] ; then
                echo $"$prog already running"
                return 0
        $eg_daemon -p $pidfile -l $logfile $OPTIONS
        [ $RETVAL = 0 ] && success || failure
        return $RETVAL

stop() {
    if [[ -f ${pidfile} ]] ; then
        pid=$( cat $pidfile )
        isrunning=$( ps -elf | grep $pid | grep $prog | grep -v grep | awk '{print $4}' )

        if [[ ${isrunning} -eq ${pid} ]] ; then
            echo -n $"Stopping $prog: "
            kill $pid
            echo -n $"Stopping $prog: "
    return $RETVAL

reload() {
    echo -n $"Reloading $prog: "

# See how we were called.
case "$1" in
    status -p $pidfile $eg_daemon
    echo $"Usage: $prog {start|stop|restart|force-reload|reload|status}"

exit $RETVAL

Control Arduino from Raspberry Pi with pyFirmata

Although Raspberry Pi and Arduino are two different hardware in terms of their applications and structure, but they both are considered as two competing open source hardware platforms. They both have very strong community and support. Today we will slightly change things, and show you how we can take advantage of both of them. If you have both Arduino and Raspberry pi boards, this article will show you how to use Raspberry pi and Python to control the Arduino.

We will use PyFirmata firmware to give commands to Arduino using Raspberry Pi python script. PyFirmata is basically a prebuilt library package of python program which can be installed in Arduino to allow serial communication between a python script on any computer and an Arduino. This python package can give access to read and write any pin on the Arduino. So here we will run python program on Arduino using Raspberry pi.

So in this tutorial we will take advantage of this library and will use this in our Arduino board to control Arduino using Raspberry Pi.


  1. Raspberry Pi with Raspbian OS installed in it
  2. Arduino Uno or any other Arduino board
  3. Arduino USB cable
  4. LED

In this tutorial I am using External Monitor using HDMI cable to connect with Raspberry Pi. If you don’t have monitor, you can use SSH client (Putty) or VNC server to connect to Raspberry pi using Laptop or computer. If you find any difficulty then follow our Getting stared with Raspberry Pi Guide.

Installing PyFirmata in Arduino using Raspberry Pi

To upload PyFirmata firmware in Arduino, we have to install Arduino IDE in Raspberry Pi. Follow these steps to install:

Step 1:- Connect the Raspberry Pi to the internet. Open command terminal and type the following command and hit enter

sudo apt-get -y install arduino python-serial mercurial

Wait for few minutes, it will take time. This command will install the Arduino IDE in your Raspberry Pi.

Step 2:- Now, we will install pyFirmata files using the given github:

git clone

Then run the following command:

cd pyFirmata
sudo python install

Step 3:- We have installed all the required files and setups.

Now, connect your Arduino board with Raspberry Pi using USB cable and launch Arduino IDE by typing arduino in terminal window.

Step 4:- Then type lsusb command to check whether Arduino is connected with your raspberry pi.

In Arduino IDE, Go to tools and choose your board and Serial Port.

Step 5:- Upload the PyFirmata firmware on the Arduino by clicking File -> Examples ->  Firmata -> Standard Firmata and then click upload button . As shown below.

We have successfully installed the pyFirmata firmware in the Arduino board. Now, we can control our Arduino using Raspberry Pi.

For demonstration we will blink and fade an LED on the Arduino by writing python codes in Raspberry Pi.

Code Explanation

For coding part, you should read documentation of pyFirmata for better understanding. We will use pyFirmata functions to write our code. You can find pyFirmata documentation by following the link.

So let’s start writing the code

Open your favorite text editor on the Raspberry Pi and import pyFirmata library.

import pyfirmata

Define pin on the Arduino to connect the LED

led_pin = 9

Now, we have to write serial port name on which Arduino board is connected using pyfirmata.Arduino() function and then make an instance by assigning port in board variable.

board = pyfirmata.Arduino("/dev/ttyACM0")
print "Code is running”

In while loop, make led pin HIGH and low using[].write() function and give delay using board.pass_time() function.

while True:[led_pin].write(0)
    board.pass_time(1)   [led_pin].write(1)

Our code is ready, save this code by putting .py extension to the file name.

Open command terminal and type python to run the code on the Arduino board. Make sure your Arduino board is connected with your Raspberry Pi board using USB cable.

Now, you can see Blinking LED on the Arduino board.

Complete code for blinking LED using pyFirmata is given at the end.

Fading LED on Arduino using pyFirmata

Now, we will write code for fading the LED to make you more familiar with the pyFirmata functions. This code is easy as previous one. You have to use two for loops, one for increase brightness and other for decrease brightness.

In this code, we have defined the pins in different way like led = board.get_pin(‘d:9:p’) where d means digital pin. This is function of pyFirmata library. Read the documentation for more details.

Complete code for Fading LED using pyFirmata is given at the end.

Now, you can add more sensors to your system and make it more cool, check our other Arduino projects and try building them using Raspberry pi and python script.


Python code for LED blink:

import pyfirmata

led_pin = 9

board = pyfirmata.Arduino(“/dev/ttyACM0”)

while True:[led_pin].write(0)


Python code for Fading LED:

import time
import pyfirmata

delay = 0.3
brightness = 0

board = pyfirmata.Arduino(“/dev/ttyACM0”)

led = board.get_pin(‘d:9:p’)
while True:
# increase
for i in range(0, 10):
brightness = brightness + 0.1
print “Setting brightness to %s” % brightness

# decrease
for i in range(0, 10):
print “Setting brightness to %s” % brightness
brightness = brightness – 0.1

Arduino and cpp files

You can create an Arduino project in which you have a main .ino file with setup() and loop(), but all the stuff in .h and .cpp files.

Best Javascript charting libraries

Check this link