Measuring Mobile Internet Speed

As more and more I have started using public transportation for my daily commute to work internet connection has become a necessity during my travel. Good thing is that there is free WIFI on the train although quality of internet varies depending on location during ride, sometimes it is good and sometimes connection is slow or drops completely. I am not blaming bad service by transportation company, similar situation I am getting when using my personal hotspot.

I am curious enough so I have decided to measure these “black areas” and to do that I would need some way of determining signal strength and get exact location where signal is measured. The location is quite easy I have to log GPS coordinates and idea for signal strength came to me on its own. Apparently 4G router located on the train is assessing signal strength all the time and the values can be extracted with HTTP request.

Routers version of signal strength is only one feature for the connection which is measured in this case, better implementation would be doing quick speed tests to measure overall internet speed quality.

Getting signal strength value

After doing quick investigation on router home page, I have found that there are various router stats available like connection mode, connection strength, battery levels, this you can see in image below.

These statuses are refreshed at regular time intervals and web site is rendering these results. I have discovered, that by sending a simple request to available endpoint it is returning same information in neat, formatted XML string.

So now I have my signal strength value, next would be adding location dimension to the captured data.

Getting location

To get GPS coordinates I was using “Bluetooth GPS Output” by Meowsbox application running on mobile device and when I connect laptop, location information is streamed through one of COM ports. Reading location was effortless using Python serial library. More details on how to connect mobile app to laptop or PC is available in the app, there are nice descriptions and YouTube videos as well.

GPS output

Above you can see that mobile device is tracking location and streaming that to COM port.

Now I have both, signal strength value mapped to a geographical location. To log values I have made a python application that every 15 seconds sends HTTP requests to get signal strength value and captures GPS location data and then stores those values in CSV file for later analysis.

Analysing Data

Just when I have boarded train I had to enable Bluetooth for all the devices, start up GPS coordinates streaming and start up Python application that is logging all the values, I was driving like that for a while till I got over thousand data points. Below is quick plot of signal strength values. From returned results I have identified 6 signal strength levels 1 is lowest and 6 is having high signal strength.

As point density is very large if I am not seeing all the points at once they are getting placed on top of each other and I think it is not giving accurate results. Better results would be achieved if I would have broken down line in smaller local regions for which the average value is calculated, for example region could have 100 meter radius with an average signal strength value there.

Conclusions

Only relying on Router data is not sufficient, because connection can have high value although the throughput for connection is bad. Better solution would be by doing speed tests measuring connection speeds and logging those values. Another variable that I might need to consider would be count of devices connected to that public WIFI network as data consumption from other devices can have considerable impact.

Thanks for reading, if you liked, disliked, have suggestions on what could be changed or upgraded let me know.

Stepper motor as a brake – Failed

I have started building this prototype to automate carbon fiber tube winding process. Currently at the end of the task I have to apply shrink-tape by manually holding the roll in hand and guide that along the mandrel. Significant improvement would be applying same tape using machine gantry which is feeding the tape on mandrel with constant force. For constant feeding force I would need drag torque on shrink-tape roll axis.

Unfortunately my attempt described in this post failed and I will have to look for another option, anyway it was interesting to fail and now it is more clearer.

Shrink-tape braking test unit

Before I was starting building prototype I did calculations to estimate needed torque to hold required tension force. Although stepper used for this prototype does not hold needed torque, my intention here was to test the idea. Another benefit that I expected to have with this variant was some degree of control when variable resistor is connected to motor wounds and when resistance is changed torque changes. A day before I have experimentally found needed resistor range which was from 0 ohms to 500 ohms.

All calculation values were captured and a graph was drafted where on Y-axis you can see calculated torque value. When tube is wound shrink-tape roll diameter changes what gives torque increase and different color lines represent different tension forces for different diameters when tape is unwinding.

Braking torque calculations

Afterwards CAD model was created with Fusion 360 and parts produced using some plastic material laying somewhere in workshop. Here below is fabricated one of the pulleys.

Milled part from plastic

When all was assembled I could give it a try, after light pull I understood that idea has failed. Braking unit was not holding torque, as I was pulling the tape, I was feeling some resistance, but as I increased speed torque disappeared and it started to slip. I had a slight doubt that this could happen, but I was hopeful. It worked for small speeds, but was not working for my application.

Concept was tested and showed not to be working for this application, I have feedback now, I can readjust and attempt another option. Now I am thinking of making a torque motor with large diameter with opposite rotation direction. Have to do some calculations, some search and thinking. Till later!

Interfacing with Logo 8 using Modbus TCP

I am currently working on a project related with smart home and for my use-case I have chosen Siemens Logo 8 controller as a main brain device. One thing that I like very much about this Logo generation over previous, that it comes with integrated Modbus TCP functionality. This is very useful, because instead of interfacing with device using digital inputs and outputs I am able to transfer flag and numeric values through Modbus TCP connection to any device which is supporting this protocol. This helps building custom HMI with specific functionality or expand with custom peripheral devices or connecting industrial equipment through Modbus TCP.

My setup consists of Logo 8 controller together with 24V power source. Using Ethernet cable it is connected to home TP 10/100 switch which is linking Raspberry Pi LCD and my laptop.

Schematic view of my setup

For Logo I have added 7 input buttons and one analogue input which is connected to variable resistor, for now all relay outputs are not connected to anything, but their operation can be spotted by sound which is made when contact is made and that is enough for me at this point.

To interface with Logo device I am using Python library uModbus that creates connection and is communicating values between devices. With Python I am changing or reading specified memory section which is reserved on Logo, all memory mapping information can be found in Siemens Logo datasheet.

Logo! Soft Comfort program example

In Logo program above I have added digital Input M1 which is changed from Modbus TCP client (in this case Raspberry Pi) and then turning on/off the relay. Modbus TCP packets can be transferred ower ordinary Ethernet network.

Reading analogue value in Logo! Soft Comfort

Following code is taken from uModbus description page example code and adjusted for my setup. In example above I am reading analogue value from my A1 (analogue input 1), when variable resistor is turned, then changed value is reflected on Python console screen. Below Python code example.

Reading analogue values code example

import socket
from umodbus import conf
from umodbus.client import tcp
from time import sleep as wait

# Enable values to be signed (default is False).
conf.SIGNED_VALUES = True

### Creating connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('192.168.0.3', 502))

### Reading Analogue value from associated Input Register
message = tcp.read_input_registers(slave_id=1, starting_address=0, quantity=1)

### Printing analogue values in Python console
for i in range(1, 100000):
    response = tcp.send_message(message, sock)
    print(response, i)
    wait(0.01)

sock.close()
print("Transfer ended!")

Setting Logo coil value code example

import socket
from umodbus import conf
from umodbus.client import tcp

# Enable values to be signed (default is False).
conf.SIGNED_VALUES = True

### Creating connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('192.168.0.3', 502))

message = tcp.write_multiple_coils(slave_id=1, starting_address=8256, values=[1, 0, 0, 0])

# Response depends on Modbus function code. This particular returns the
# amount of coils written, in this case it is.
response = tcp.send_message(message, sock)
print(response)
sock.close()
print("Transfer finished")

In conclusion – Modbus TCP functionality in Logo controller is very powerful thing, that expands Siemens Logo controller integration with different devices that are supporting this interface. It gives you more flexibility in choosing peripherals and one can develop own HMI solutions.

One thing that I have not added to this stage of the project was VPN connectivity to this workbench. For that I am missing router that is supporting PPTP connectivity. PPTP client connection would enable controlling this setup remotely from any part of the world, this enables monitoring different statuses of logs, capturing and storing different analogue and flag values in database.

For easier Python code transfer to Raspberry Pi I suggest setting shareable folder on Raspberry Pi that can be accessed on devices on local network.

Source

Bluetooth audio in Workshop

This was a quick project making a Bluetooth audio box for the workshop, because old radio device was drifting away from station all the time. It took me some time to ripe for this as it is time consuming and costs extra money to get speakers, power unit and some buttons. The audio Bluetooth module has been laying around for some time already on the table waiting for the right moment.

Initially it was planned to add a USB fast charging port, but it took too long to arrive and I have skipped this idea, but if you plan to replicate same you definitely should add one, then you can charge your phone while listening to music.

In this post I have listed some images on how it was made and box drawings as well as list of components used, in case you plan to replicate the same.

Rotating box

Link to drawings of box assembly.

Components:

If you need additional information, other drawings or assembly file do not hesitate, let me know.

Robot precision measurements with LED

With this activity my goal was to evaluate how straight lines robot can go and to enable me to “see” robot movement I was tracking LED light with camera long exposure shoot. To make photograph clean with no positioning movements captured, I had to control LED when it is turned on and off. One very useful software for this task was RoboDK which allows to program robot and simulate all axis movements. This software is simple, easy to uses and it has nice 30 day trail period.

Controlling LED

My KUKA KRC2 controller is equipped with digital I/O interface card and it’s output was used to drive relay that turned on and off the LED light. Below you can see a prototype board that was made and fixture where LED was attached. These two wires that you are seeing that are connected to the board are connected to relay that is driven by KUKA controllers Output. It is a simple command in robot code that sets particular output to needed level high or low, which then latches relay contact and toggles LED light.

LED light mounted on robot arm

Movement generation

For movement generation and simulations I was using RoboDK software. This application is intuitive and fairly easy to use. I had a drawing of circle and square pattern that I wanted to have and with RoboDK I was able to generate G-code, that you can see in image below. After simulations and fixing robot singularities code could be exported to robot controller. One thing that I had to add manually in robot code was setting controller output high and low to drive LED.

RobotDK program testing

Movements captured

When code was loaded in controller I ran it through several times in test mode to make sure it is safe and it does not have singularities and axis are not exceeding speed limits. I had to return back to RoboDK several times to change tool orientation in order to avoid extensive axis speeds and eventually I had a code that I was able to launch on full speed

I was glad to see that lines were clean, parallel and there were no vibrations or pulsations on movement path. In images you can see distortion due to wide angle lens used and camera placement, but it gives needed information anyway.

Circle pattern
Square pattern

Sources

  1. RoboDK software – https://robodk.com/

Logging workshop environment

Already some time ago I have purchased Raspberry PI zero w a small computer with WiFi connectivity and I have paid for it not more than 20 EUR together with shipping, it is small but with rich number of applications. In this case I came up with an idea to build IoT that will be logging environment at my workshop and all will be neatly displayed in Google spreadsheet.

When I was starting winter was just coming and with such device I could monitor temperature in workshop and if it drops below some certain point I will know that I have to turn on heating. Data is being written in Google spreadsheet it is possible to add Google Apps scripts and receive notifications if a certain condition is met, then you will never miss when heating has to be turned on.

To add some senses to my “Zero” device I have added to it Enviro Phat then by importing python library I was able to read temperature, light and pressure values, but it was missing humidity readings. For humidity readings I am using DHT22, which gives humidity value together with temperature value.

To give assembly some structure and protection I have decided to enclose electronics with poly-carbonate sheets. Parts was milled on my router here below from material which was laying in workshop.

20180117_212856
Milling poly-carbonate enclosure parts

For this project I have chosen to have simple protection for the electrical components stacked them in poly-carbonate layers.

This is how all looks together. One note here, initially I had difficulties with temperature readings because when Raspberry PI and Enviro Phat are stacked closely together it gives wrong temperature readings due to small proximity of pi chip. During normal operation it heats up so in normal room temperature reads about 35 C degrees, that is why it was needed to increase distance between these components and I have used middle poly-carbonate part to minimize error.

20180207_183937
Finished IoT assembly

So when hardware is in place i can proceed with developing python code for the device.

In python I have written code that every 30 min reads environment variables and writes these values in google spreadsheet. To set up Envro Phat it was necessary to import its library. Details on how to do that are here. And for DHT22 have installed this library. To ensure that my script is executed with 30 min frequency I am using crontab that launches python script every 30 minutes and command for that is:

00,30 * * * * (cd ~/Environment/factory/ && python environmentLog.py)
And to start edit Crontab file execute command
crontab -e
Then it come to step where Google spreadsheet has to be configured to give permission for sheet editing. Here is good YouTube video on how to configure that.
But in short needed steps for that was:
  1. On Raspberry PI zero to python you have to add following packages.
  • gspread
  • oauth2client
Use command: pip install gspread oauth2client
  1. Configure on google side and create credentials that will be used for authentication for Google services.
  2. In Google spreadsheet share it with created credentials id.
Once again, please refer to Video mentioned above.
Here is BOM with all components.
#
Item
Quantity
Total Price, EUR
Details
1
Raspberry PI Zero W
1
20
2
DHT22
1
7
3
Poly-carbonate parts
3
1
Milled poly-carbonate parts
4
25mm Pins
2
2
Connecting pins length 25 mm
5
Polyurethane spacers
19
1
Polyurethane spacers cut from pneumatic tube 6×1
6
M3 plastic washers
8
1
White plastic washers.
7
M3 nuts
7
1
M3 nuts
8
M3 bolts
7
2
M3 bolts
9
Connecting wire
1
1
DHT22 connecting wire

End words

Already see where this project can be expanded. One is adding Google app scripts that can send notifications depending on conditions it workshop. Then another idea, create a web server, add relays, so it is possible to control some appliance in workshop.

Approach to tasks…eliminate, automate, delegate

This idea is taken from one of may favorite authors Tim Ferriss. This is elimination, automation and delegation matrix.

Prepare a list of sub-tasks for your goal, add them to the list and think which of them could be eliminated, which automated and which delegated, all that remains is on you.

Task
Eliminate
Automate
Delegate
Task 1
x
Task 2
x
Task 3
have to do that
Task 4
x

Newsletter sending to Kindle

have been reading MIT Technology Review newsletter for some time already and it would be more convenient to read news on my Kindle device, but to do that I need manually load files to device and that is much work to do. Challenge was spotted, I have to automate this!

What is needed?

  1. Kindle device;
  2. Subscription to a newsletter (it can be any subscription, because script is creating HTML file from message body);
  3. Account in Google mail;

My first approach was to subscribe Kindle email directly to newsletter, but it failed because this mail is used to send documents in range of formats not plain email text  and all mails were rejected, I learned that i have to send files. One of formats accepted by Kindle is *.html, that was good news because message bodies contain html tags I only need to pack all content in html file. Solution here was to use Google script to retrieve emails one by one, then create from message body html file and then send it to kindle. As easy it sound here as easy it was to accomplish that.

Script reads emails from designated folder converts message body to *.html file which is sent to Kindle email. Then message is deleted as well as file from Google drive. I have not seen any newsletter they all are handled now they are piling up in my Kindle device. Script has one function to which trigger has been set  to run it in mornings from 6:00 to 7:00.

function send2Kindle() {

   var label = GmailApp.getUserLabelByName(“MIT newsletter”);//Folder name in email mails are read.

 var threads = label.getThreads();

   var emailTo = “your_kindle_mail@kindle.com”, subject;

 var msgStart1 = “<html><head><title>”, msgStart2 = “</title><head><body>”, msgEnd = “</body></html>”; //Had to add these tags for html file for Kindle to recognise that this is HTML file.

 // Getting newsletter

 for (var i = 0; i < threads.length; i++) {

   var msg = threads[i].getMessages(), subject = msg[0].getSubject(), body = msg[0].getBody();

   //Creating the file

   var letterFile = DriveApp.createFile(subject + ’.html’, msgStart1 + subject + msgStart2 + body + msgEnd, MimeType.html);

   //Sending mail

   MailApp.sendEmail(emailTo, subject, ‘Have a goood read! Kind regards!’, {attachments: [letterFile]});

   //Removing file

   DriveApp.removeFile(letterFile);

   //Removing message

   GmailApp.moveThreadToTrash(threads[i]);

 }

//END

}

gmail_img

In my mail account all newsletters from MIT Technology review are stored in separate folder and archived, I don’t even see them in my inbox. At the bottom I have picture illustrating that. Basically this folder is empty all the time because it is cleared in mornings.

This is  device I am using,  it may be old but I like the design of it. This Kindle does not have a touchscreen, sometimes it may be frustrating to write a WIFI name together with password using only 5 buttons.

Results: Google script successfully picks up newsletters and creates *.html file and then it is sent to Kindle email as a document attachment. Then Kindle is able to load file and lastly I am able to read news. Hope this was helpful to you, cheers!