Saturday, November 27, 2021

0000 0000 0111 1101

Orange Pi-Hole Advert killer

Recently on a video I was raging about how useless the internet was becoming with all the adverts. One comment underneath spurred/shamed me into action:


As it turns out my Raspberry Pi box of SBCs was emptier than I remembered, however my Orange Pi box was replete with possibly suitable SBCs, including an Orange Pi PC left over from a previous blog and video.

I liked the auto-cooling version I had previously made, and now seemed like a good time to press it into service cutting out all of those pesky online adverts!

The Pi-Hole advert blocking project has a bit of history now, and the community behind it is mature and productive. Due to my nerdiness I went to their github site and followed installation and tips etc. The software installed fine over the top of armbian for the Orange Pi PC.

There were a few weird hiccups along the way (aren't there always?):

1. The startup script for the fan (see this link) did not work, due to (new?) requirements that startup scripts have START|STOP|RESTART|ETC blah blah which I don't quite understand at this point. Fortunately I had a working image which include the fantemp.sh script, so I used that as a base for this project.

2. I wanted to use the Orange Pi Zero 2 which would be perfect for the role - and I have one in my Orange Pi box, but software support for the H616 processor is not great at the time of making this project - if it improves then I will have a look at possibly swapping out to this SBC.

3. Router issues - my ISP issued router™ is an idiotic piece of junk. The ISP will not support a customer with any other piece of hardware (!!), so I have stuck with it for a few years - but this Christmas I have asked Santa to bring me a better router. Until then, to get to the part of the router that allows me to specify the Orange Pi(hole) as the DNS server, I need two 64 bit passwords embedded (but not hidden) in their source code <heavy sigh>. So right click, download 

4. GPIO access - to control the fan I needed access to a GPIO which then triggers an SS8050 transistor to draw enough current for the fan. Unfortunately that took a bit of a while to sort out, and in the end I used this github site to solve the problem.

5. WiFi or cable? In the end I connected the Orange Pi PC directly to the router via an ethernet cable AND I was able to power it from the router through a USB port - a neat option now sitting side-by-side with the router.










Saturday, November 20, 2021

0000 0000 0111 1100

Mailbag #8

Mail is arriving! Happy days and here is the ritualised opening of the parcels ceremony writ large on YouTube:


I haven't put any links for the products because the prices/availability is quite "fluid" at the moment...

Saturday, November 13, 2021

0000 0000 0111 1011

WiFi Repeater (Part One)

Part of the program to monitor and automate some things around the property naturally enough includes extending the WiFi network to cover a wider area. There are a number of ways of doing this, including:

1. Buying a decent router and channelling heaps of power into it for coverage
2. Buying WiFi extenders/repeaters and wiring them in all over the place
3. Coming up with some half-baked plan to use $1 ESP-01 devices running on solar power (in Tasmania!)

Of these options, which do you think this post is essentially about? 


There are a number of options for setting up such a (cheap) extended network, and it may take a few blogs/videos to explore and evaluate some options. On my list is the following:

1. Can I program the ESP-01 to accept home WiFi?
2. Which extender/repeater software for the ESP-01 suits my needs?
3. Test the network under various conditions to help me make the decision
4. Work on Solar/Battery combinations that work for spreading the network around a rural property 
5. Design and 3D print a weather-resistant project box

On the programming front, the little adapters are great, however there seem to be two main types. One is just a cradle for the ESP-01 and needs some soldering and a button added to be used as a programmer (see video), whilst the other comes with an integrated button and can be switched between "PROG" and "UART" mode.
  

Then it's a matter of choosing your programming method - you can use EsptoolEspressif's tools or (as in my case) the Arduino IDE.


Once the connections and programming was sorted (i.e. can I blink a LED!) I then used the following OTA code modified from the ESP8266 WiFi extender code:

// NAPT example released to public domain

#if LWIP_FEATURES && !LWIP_IPV6

#define HAVE_NETDUMP 0

#ifndef STASSID
#define STASSID "*****************"
#define STAPSK  "*****************"
#endif

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <lwip/napt.h>
#include <lwip/dns.h>
#include <LwipDhcpServer.h>

const char* ssid = STASSID;
const char* password = STAPSK;
const char* host = "HostName";

#define NAPT 1000
#define NAPT_PORT 10


void setup() {
  Serial.begin(115200);
  Serial.printf("\n\nNAPT Range extender\n");
  Serial.printf("Heap on start: %d\n", ESP.getFreeHeap());

#if HAVE_NETDUMP

#include <NetDump.h>

  void dump(int netif_idx, const char* data, size_t len, int out, int success) {
    (void)success;
    Serial.print(out ? F("out ") : F(" in "));
    Serial.printf("%d ", netif_idx);

    // optional filter example: if (netDump_is_ARP(data))
    {
      netDump(Serial, data, len);
      //netDumpHex(Serial, data, len);
    }
  }
#endif

#if HAVE_NETDUMP
  phy_capture = dump;
#endif

  // first, connect to STA so we can get a proper local DNS server
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(500);
  }
  Serial.printf("\nSTA: %s (dns: %s / %s)\n",
                WiFi.localIP().toString().c_str(),
                WiFi.dnsIP(0).toString().c_str(),
                WiFi.dnsIP(1).toString().c_str());

  // give DNS servers to AP side
  dhcpSoftAP.dhcps_set_dns(0, WiFi.dnsIP(0));
  dhcpSoftAP.dhcps_set_dns(1, WiFi.dnsIP(1));

  WiFi.softAPConfig(  // enable AP, with android-compatible google domain
    IPAddress(172, 217, 28, 254),
    IPAddress(172, 217, 28, 254),
    IPAddress(255, 255, 255, 0));
  WiFi.softAP("WiFi-Mesh", STAPSK);
  Serial.printf("AP: %s\n", WiFi.softAPIP().toString().c_str());

  Serial.printf("Heap before: %d\n", ESP.getFreeHeap());
  err_t ret = ip_napt_init(NAPT, NAPT_PORT);
  Serial.printf("ip_napt_init(%d,%d): ret=%d (OK=%d)\n", NAPT, NAPT_PORT, (int)ret, (int)ERR_OK);
  if (ret == ERR_OK) {
    ret = ip_napt_enable_no(SOFTAP_IF, 1);
    Serial.printf("ip_napt_enable_no(SOFTAP_IF): ret=%d (OK=%d)\n", (int)ret, (int)ERR_OK);
    if (ret == ERR_OK) {
      Serial.printf("WiFi Network '%s' with same password is now NATed behind '%s'\n", "Charis-Mesh", STASSID);
    }
  }
  Serial.printf("Heap after napt init: %d\n", ESP.getFreeHeap());
  if (ret != ERR_OK) {
    Serial.printf("NAPT initialization failed\n");
  }
  ArduinoOTA.setHostname(host);
  ArduinoOTA.setPassword("MyPass");
  ArduinoOTA.onError([](ota_error_t error) {
    (void)error;
    ESP.restart();
  });
  /* setup the OTA server */
  ArduinoOTA.begin();
  Serial.println("Ready");

}

#else

void setup() {
  Serial.begin(115200);
  Serial.printf("\n\nNAPT not supported in this configuration\n");
}

#endif

void loop() {
  ArduinoOTA.handle();
}

The video below shows this system in a link of WiFi SSIDs stretching about 60m down the driveway as per this diagram:

I'm currently evaluating a slightly different way of putting the network "Mesh" together, but I'll save that for another video/blog.









Saturday, November 6, 2021

0000 0000 0111 1010

Mailbag #7

The mail is dribbling in at the moment - here is a collection of items from the last week or so.