Tuesday 31 December 2019

TTY control codes and ASCII esacpe sequences

ASCII escape sequences
ASCII escape sequences start with ESC followed by a number of bytes.
The ESC code is 033 in octal and 27 in decimal

A terminal will respond to escape codes that are output to it. Typing an escape code on keyboard by pressing ESC followed by  sequence is treated as an input by the terminal and the it will not act on it therefore you need some way to echo the escape sequence back to the terminal as output for it to action it.

Linux example
echo -e "\033[31;1;4mHello\033[0m"

Powershell example
PS C:\Users\pdj10> $esc = "$([char]27)" # 27 is the escape character
PS C:\Users\pdj10> write-host "$esc[32m hello"  # print hello in green
 hello
PS C:\Users\pdj10>


^L - clear the screen.
^V - take the next character literally e.g. typing ctrl-V followed by ctrl-l the terminal will display '^L' and not clear the screen.

Ableton Focusrite Saffire 6 ASIO setup


The ASIO drivers are the best drivers to use.

How to configure Focusrite Saffire 6 ASIO driver in Ableton 10.

Select the ASIO driver type in Ableton Options | Preferences | Audio.

To avoid poor sound quality due to re-sampling ensure the in/out sample rate in Ableton matches the default format in the Windows 10 Sound Settings | Device Properties | Additional Device Settings | Advanced.
Ableton Options | Preferences | Audio



Windows 10 Sound Settings

If you want multiple applications to be able to use the Saffire at the same time you need to ensure Exlusive mode is not enabled in the Windows 10 Sound Settings | Additional Device Settings | Advanced.

Additional Device Settings | Advanced



NB The Live manual states the buffer size should be set to a multiple of 2 e.g. 512

Saturday 21 September 2019

Powershell - how to find which process owns a port



Use get-netTCPConnection with the -localport option to return details for a specific local port.

get-netTCPConnection -localport 9945

LocalAddress  LocalPort RemoteAddress  RemotePort State         AppliedSetting OwningProcess

------------  --------- -------------  ---------- -----         -------------- -------------
0.0.0.0       9945      0.0.0.0        0          Bound                        9376
192.168.76.31 9945      151.101.16.133 443        Established Internet         9376


Altertatively, use the old Netstat command. -o returns the owning process id. Use Select-String to filter on a specific port
e.g

 netstat -o | Select-String -pattern 8243
                          
  TCP    192.168.76.31:8243     52.142.84.61:https ESTABLISHED     9952



Get-process returns proceses information. -id returns details for a specific process id
e.g.

get-process -id 9952
Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    829      50    18744      55440       6.67   9952   2 OneDrive


Sunday 15 September 2019

Configure pfSense SSH access

How to configure pfSense for SSH access using both key and password

Step 1 - Generate SSH key pair


Generate a SSH key pair for each user you want to grant access: 
- Use PuTTY Key Generator (puttygen.exe) to generate a public/private key pair. Select RSA type of key and click Generate

- Add a key passphrase [1] to secure the saved private key 
- Save the public key

- Save the private key file [2] somewhere safe (keep this file secure)
- Select the text in the box labelled "Public key for pasting into OpenSSH_authorized_key files and save that to a file e.g pubOpenSSH. You will need this text later [3]

Step 2 - Enable SSH access

Enable SSH access on the pfsense box and require both a password and public key for SSH access:
- log in to the pfsense GUI
- Navigate to System > Advanced > Admin Access
- Enable (tick) 'Enable Secure Shell'
- Select 'Require Both Password and Public Key'
- Save

Step 3 - Grant user SSH access

Set the SSH key for each user account:
- Navigate to System > User Manager > Users
- Select Edit User for the user you want to grant SSH access
- Paste the text from earlier [3] into Authorized SSH Keys
- Save 

Step 4 - config PuTTY SSH

Config PuTTY for SSH connection using public key
- run PuTTY
- set hostname
- select connection type SSH
- give your session a name in Saved Sessions
- Navigate to Connection > SSH > Auth and add the the private key file for authentication [2]
- go back to Session and click Save to save these session settings

Step 5 - connect via SSH

Connect using SSH
- Run PuTTY (if not already running)
- Click the saved session from step 4 and click Load
- Click Open to initiate a connection
- At login as: prompty enter username
- Enter passphrase used to protect the private key [1]
- at prompt for the user's password enter the user's password

That's it you are now connected to the pfsense box via SSH using both a key and password



Sunday 18 August 2019

How to compile Angband on Windows


Step 1 - Clone the Angband git repository

Not necessary but allows you to make changes to Angband and submit those changes back to the main project

Step 2 - install MinGW


Step 3 - add latest commits to your cloned repository

If there have been updates to the main angband project since you cloned it you can add those commits to your clone as follows

Using powershell in the local angband directory run the following commands
git pull https://github.com/Angband/angband.git master
git commit
git push


NB if the git tags are not correctly updated try the following to pull the latest tags from the angband git and push them to the cloned repository
git pull --tags https://github.com/Angband/angband.git master
git push --tags

Step 4 - Compile Angband on Windows using MinGW

run msys.bat

In the mingw shell run the following commands
    cd to the local angband directory e.g. cd C:/Users/pdj10/Documents/_PROGRAMMING/AngbandPDJ102fork/angband
    ./autogen.sh
    ./configure --enable-win
    make

Following build, to get the program to run, you need to copy the executable
from the src directory into the top-level dir, and copy 2 DLLs (libpng12.dll
and zlib1.dll) from src/win/dll to the top-level dir

Sunday 23 June 2019

PiDP-11/70 Running light program


The following PDP-11 assembler program can be toggled into the front panel of the PiDP-11/70 and causes a "Running light" to be displayed on the data leds. This program is from the retrocmp.com web-site.


adress  data      opcodes operation on switches


001000  005000    clr     r0
001002  005200    inc     r0
001004  006100    rol     r0
001006  000005    reset
001010  000775    br      001004

activate HALT
data switches=001000, LOADADRS
data switches=005000, DEP
data switches=005200, DEP
data switches=006100, DEP
data switches=000005, DEP
data switches=000775, DEP

Start sequence:
de-activate HALT
data switches=001000, LOADADRS
START

The upper "ADDR SLECT" knob must be in the CONS PHY position, and the lower ADDR SELECT knob must be switched to DATA PATHS.

PiDP-11/70 kit build

The PiDP-11/70 is a modern replica of the PDP-11/70. All the buttons and lights are fully functional and it uses a RaspberryPi to run original PDP-11 software and operating systems.

PiDP-11/70

The PiDP comes as a kit

Part of the PiDP-11/70 kit


Terminal connection to the PiDP-11/70 console showing the available Operating Systems to boot.

Terminal connection

The PiDP-11/70 console runs using the linux Screen utility which provides virtual terminals which you can switch between.

  • Type Ctrl-a d to detech from the virtual terminal and drop back into the linux terminal
  • Type sudo screen -r to reattach to the PiDP-11/70 virtual terminal. The startup screen script is run under root hence the need to run screen with sudo to re-attach. 
  • Type Ctrl-a ? to view Screen help pages


Sunday 26 May 2019

Dragino LoRa Shield for Arduino


The Dragino LoRa Shield for Ardunio enables your Arduino to transmit and receive data packets wirelessly many kilometers using the LoRaWAN network for free. There is no need for wifi or 3/4/G network connections.


Arduino Dragino Shield (red) plugged into a MEGA2560 Arduino

LoRaWAN

LoRaWAN is a wireless protocol for wide area networks which uses the unlicenced 863-870 MHz frequency band in Europe. Other parts of world use other unlicenced frequencey bands.

So that many devices can all share the same frequency band the European frequency regulations impose specific duty-cycles on devices for each sub-band. These apply to each device that transmits on a certain frequency and devices have to respect these duty-cycles. Most channels used by LoRaWAN have a duty-cycle as low as 1% or even 0.1% which means in pratice you can only transmit or receive small amounts of data.


LoRaWAN is implemented using the proprietary LoRa modulation system sold by Semtech corporation.
The LoRaWAN protocols are defined by the LoRa Alliance and formalized in the LoRaWAN Specification which can be downloaded on the LoRa Alliance website.


Dragino LoRa Shield

The Dragino LoRa Shield is a LoRaWAN transceiver in a Arduino shield form factor that uses the Semtech SX1276/SX1278 chip and costs around £25.

http://www.dragino.com/products/module/item/102-lora-shield.html


The Things Network

The Things Network is a project dedicated to building a network for the Internet of Things based on LoRaWAN.

LoRaWAN Gateways connect to the The Things Network and forward received data packets from LoRaWAN Devices to The Things Network cloud service which in turn forwards them on to your Internet connected application. It can also send data packets from your application to devices.


There are plenty of gateways available to connect to - if you'd like to find a gateway in your area, check the Gateway Map. If there are no gateways available locally it is simple to setup your own and connect it to the The Things Network. 

First transmission attempt

To set up your Arduino as an The Things Network device and transmit a message you need to
  1. Regsiter with The Things Network, create an application and register your device with the application. In settings set the registered device to use ABP activiation and make a note of the Network Sesion Key, application session key and Device address.
  2. Using Arduino IDE > Library Manager - install the IBM LMIC framework library
  3. Using the Arduino IDE - use the ttn-abp example from the LMIC library. Modify the source code to use the NWKSKEY, APPSKEY and DEVADDR as noted above and flash to your arduino.
  4. Your arduino will tranmist a message "hello world" once a minute. If this message is received by a Things Network Gateway you can see it appear in the data tab as shown below. 

Test packets received



The details of one of the test packets is shown below. You can see it was received by two Gateways which are about about 1km and 1.5km away. This seemed impressive given then the Arduino was indoors.  

Test packet details





Saturday 27 April 2019

First impressions LoLin NodeMCU V3

The LoLin NodeMCU v3 is a breadboard compatible development board combining the popular ESP8266 Wifi module with an USB connector for power and serial programming.


LoLin NodeMCU v3

LoLon NodeMCUv3 pinout

 

Connecting to the serial port

Connect the LoLin NodeMCU to a PC via the USB serial port and use serial console software at 115200 baud to connect e.g. PuTTY or the Arduino IDE serial monitor.

Press reset and the LoLin NodeMCU v3 will display some garbage (this is a boot message which uses a different baud rate during boot) followed by 'Ready' once booted, depending on the firmware installed. 

Firmware

There are several different 'standard' firmwares available for ESP2866 based devices which can be confusing.

Two of which are the AI-thinker firmware which supports AT commands and the NodeMCU firmware which includes a LUA interpreter.     

Out of the box my NodeMCU device did not respond to any AT commands but did provide an wi-fi Access Point and DHCP service for connecting wireless devices but offered no open ports. Possibly it is running the NodeMCU firmware?

Serial port output on first boot


Flashing with ai-thinker-0.9.5.2-115200.bin firmware

ESP38266 devices can be flashed with a different firmware. To flash with the ai-thinker firmware


1) Download the NodeMCU Flasher Master software
2) Download the ai-thinker firmware
3) Start nodemcu-flasher-master > Win64 > Release > ESP8266Flasher software
4) Select the firmware to flash. Config > first wheel > select ai-thinker firmware
5) Flash the ESP8266. Operation > Flash
6) Once complete. Reset the LoLin

Running the ai-thinker firmware the ESP8266 now responds to AT commands on the serial port. 

Serial port output after flashiing with AI-thinker firmware

 

The following website is a good source of supported AT commands.

A port scan of the newly flashed firmware revealed no open ports. Running the commands AT+CIPMUX=1 and  AT+CIPSERVER=1,80 configures a web server and the serial output will show debug details of received requests. The web server is not very useful as it servers no web-pages and you can't configure the device via it.

Using the Arduino IDE

The best way to use the device is to program it with your own programs (sketches) using the Arduino IDE and ESP8266 board managers.


If you receive the following error message when flashing the board ensure NodeMCU 0.9 (ESP-12 Module) is selected in Tools > Board.  The Arduino IDE uses the selected board type to perform a board specific reset procuedure when flashing.

warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed



Monday 22 April 2019

Prototype IoT Plant Monitor

The prototype IoT Plant Monitor measures temperature, humidity and soil moisture levels and transmits the data to the Blynk IoT cloud.

A mobile phone app can then be used to monitor the data and view both historical and real-time updates.

The prototype is built using 


Prototype IoT Plant Monitor




Prototype IoT Plant Monitor iOS app

GitHub:

https://github.com/pdj102/PlantMonitor

AM2302 Humidity and Temperature Sensor Module

The AM2302 (DHT22) is a calibrated relative humidity and temperature sensor module with a single data line for data exchange.  It has a small micro controller which uses a proprietary protocol.

AM2302 sensor module


Pin Out:
1. VDD 3.3V to 6V
2. DATA
3. N/C (not connected)
4. GND

Measurement:
  • Humidity: 0 to 100% 
  • Temperature: -40 to 125 degrees Celsius

Accuracy:
  • humidity+-2%RH(Max+-5%RH)
  • temperature+-0.2Celsius

In applications, an external pull-up resistor, about 10 - 5kΩ, is often required. Sometimes this resistor is already integrated in the module, sometimes its necessary to add it.


Arduino IDE

Numereous Arduiono IDE libraries exist for the DHTxx family of modules.  For ESP8266 try https://github.com/beegee-tokyo/DHTesp which disables task switching during reads to ensure timings are not affected.






Soil Moisture Sensor - MH-Sensor Series, Flying-Fish


The Soil Moisture Sensor from MH-Sensor Series, Flying-Fish, provides both a Digital (High or Low) and an Analogue output.

The module has four pins
  •     VCC: For power (2V to 36V)
  •     A0: Analog output
  •     D0: Digital output
  •     GND: Ground
The module also contains a potentiometer which will set the threshold value and then this threshold value will be compared by the LM393 comparator. The output LED will light up and down according to this threshold value.

Soil Humidity Sensor (MH-Sensor Series Flying-Fish)
 Connected to a 5V supply the analogue output measured as follows
  • In air - 5V
  • Wet soil - 2V
  • Water - 1.9V


Saturday 20 April 2019

Programming ESP8266 Arduino Shield using Arduino IDE


The ESP8266 Arduino Shield can be programmed using the Arduino IDE.

Install the ESP8266 board Managers

Go "To File > Preferences", and set Additional Boards Manager URLs: to include http://arduino.esp8266.com/stable/package_esp8266com_index.json 

NB multiple board manager URLs can be seperated with a comma

Go to "Tools -> Board -> Boards Manager", type "ESP8266" and install it.

Go to "Tools -> Board" and select "Generic ESP8266 Module".

Connect ESP8266 to PC 

Connect ESP8266 Shield debug port to PC via USB to TTL Serial board.
  • RX to TX
  • TX to RX
  • GND to GND
  • 3V3 to 3V3

Set DSP8266 to flash mode

Set DIP switches 3 (flash mode) and 4 (DFU) ON

Upload sketch program

Open sketch program and select upload

Set DSP8266 to normal operation and run sketch program

Set DIP switches 3 (flash mode) and 4 (DFU) OFF


Sunday 14 April 2019

Connecting to an Arduino ESP8266 Shiald v1.0



The Arduino ESP8266 Shiald v1.0 is an Arduino UNO format shield for an ESP8266 WiFi module.

The ESP8266 WiFi module is a self contained SOC from Espressif Systems with TCP/IP stack and WiFi capability enabling any microcontroller to access a WiFi network. Out of the box the ESP8266 Shiald module is capable of operating independently without an Arduino Uno being attached

There are many different Arduino ESP8266 Shialds out there that look almost identical but come with different default software installed and variances in circuitry.


This article is about two such Shialds and describes initial findings when connecting to the board debug port from a PC and the default Access Point.

The vendor of the first Shiald is AI-THINKER and the second DOIT.AM. The names are marked on the ESP8266 module case.
AI-THINKER and DOIT.AM ESP8266 shialds

Shiald DIP settings

The Shiald has 4 DIP switches as follows (when ON):
  1.  Connect ESP8266 TX to pin D0
  2.  Connect ESP8266 RX to pin D1
  3.  Enable ESP8266 bootloader mode
  4.  Enable DFU led (purpose?)
To run the programmed software ensure DIP 3 is OFF.  To flash new software to the ESP8266 ensure DIP 3 is ON.

NB the debug TX and RX pins are permenantly connected to the ESP8266 TX and RX.

Connecting Shiald to PC via USB to TTL serial adapter

To connect to the Shiald debug port from a PC use a USB to TTL serial adapter.

USB to TTL serial adapter

Ensure voltages are matched e.g both USB to TTL serial adapter set to 5V

Connect as follows:

  • Shiald Debug RXD <-> TX

  • Shiald Debug TXD <-> RX

  • Shiald Debug GND <-> GND

  • Shiald Debug 5 V <-> VCC

PuTTY connection to Shiald Debug port

To interact with the Shiald Debug port from your PC use software like PuTTY.

Use the following serial settings
  • COM port to the USB to TTL serial adapter COM port
  • baud 115200

Shiald AI-Thinker


Connecting to Shiald Board debug

Pressing reset on Shiald results in the following output

Debug output from THINKER-AI Shiald

In this case the Shiald is running SDK version 0.9.2. It is using the network 192.168.4.0/24 for the wLAN, the server itself is using the IP address 192.168.4.1 and providing a DHCP service for wLAN client devices.

Many web pages state the AI-THINKER software is capable of processing AT commands. For example, sending the command 'AT' the shiald will respond with an 'OK' message.

The AT commands must end with "\r\n".  By default, PuTTY sends CR (\r) when the Enter Key is pressed therefore press Ctrl+M to send CR (\r) and Ctrl+J to send LF (\n).

Unfortunately, I was unable to get my AI-THINKER shiald to response to any AT commands. I checked the wiring and confirmed the commands were being sent but the board was unresponsive.

Connecting to AI-Thinker Shiald  Access Point wLAN

By default the board acted as an Access Point with SSID AI-THINKER and default password ai-thinker. In the debug window you see output indicating when a client wLAN deviceconnects. 

iPhone connected to Shiald wLAN

The AI-Thinker shiald web server

The AI-Thinker Shiald runs a web browser on port 80  (this is the only open port on the shiald)

To test wifi connection from your wifi device go to  http://192.168.4.1/client?command=0

Web page http://192.168.4.1/client?command=0

I could not find any other web pages supported by the web server.

DOIT.AM Shield

There are some boards out there with the wrong components installed preventing the D0 and D1 pins operating correctly as transistors marked J3Y have been installed instead of the required J1Y 3.3V/5V logic convertors.

The DOIT.AM I have is an example of a board with this problem. Testing with a multimeter for continuity between the TX / RX pins and D0 and D1 pins confirmed there was no connection. For testing purposes I used the debug TX / RX pins.

Connecting to DOIT.AM Shiald Board debug 

Connecting to the debug board and pressing reset on Shiald results in the following output. The default software on this board responds to AT commands. 

Debug output from DOIT.AM Shiald

Connecting to DOIT.AM Shiald  wLAN

The SSID is ESP_2834A6.No password required. 

The DOIT.AM Shiald web server

The DOIT.AM Shiald has no open ports which is a problem that needs further investigation (to be continued).