Browsed by
Category: Code

Wemos D1 R2 (ESP8266)

Wemos D1 R2 (ESP8266)

I am try to build a sensor with low power consumption, low enough for be battery operated. This sensor will acquire temperature and humidity readings and transmit them to my Raspberry Pi controller via HTTP requests. The Raspberry Pi will utilize a webpy service running on port 8080 to collect data from various sensors deployed throughout the home. I have previously used webpy for similar sensor projects (see my previous post here), although Node.js could have been a suitable alternative….

Read More Read More

Dynamic data with Chart.js

Dynamic data with Chart.js

  The joy of using charts on you web site! I use chart.js and I have to say after getting MySql to extract the right data I wanted to change data dynamically without a post back to the page. I have to say that I did find some examples online on how to do that with chart.js but the easier one to implement was to build the Chartjs object in a separate php page that you can call with an Ajax call….

Read More Read More

Temperature report site revamp!

Temperature report site revamp!

Finally I did it!  Still struggling with PHP.  I was thinking of using django but I thought the learning curve was too much to tackle for a side project.  Absolutely loving Bootstrap and Chart.js both so easy to use and very good looking.  Have a look at the final result here. Soon I might post some code on how I got Chart.js to post dynamic charts with AJAX.

WP backup strategy

WP backup strategy

This is my WP backup strategy: The strategy involves backing up both the MySQL database and the WordPress file system. I have successfully migrated my site to different machines and restored from various failures, and this approach has proven reliable. To back up the MySQL database, I installed automysqlbackup. This user-friendly tool simplifies the setup process and allows for flexible scheduling of daily, monthly, and yearly backups. It also offers additional features to enhance the backup process. For the file…

Read More Read More

IPaddress change alert script

IPaddress change alert script

My old ISP use to change my external IP address all the time and to keep my DNS name on track I wrote this script: #!/usr/bin/python import smtplib import urllib2 import time import sys def send_email(): try: server = smtplib.SMTP(‘smtp’, 587)#smtp address and port number server.starttls() #Next, log in to the server server.login(“smtp username”, “password”)#username and password for smtp #def emailSend(ipaddress): to_addr=”your email address” subject=”IPaddress is changed” message=”this is from your webserver:” + html from_addr=”you@gmail.com” header = ‘From: %s\n’ %…

Read More Read More

Sieve Of Eratosthenes (Still on Prime)

Sieve Of Eratosthenes (Still on Prime)

I could not make my code any better so I decided that I new approach needed to be found… Boom Eratosthenes came to the rescue. I found those two great web sites: Sieve Of Eratosthenes explained and Sieve Of Eratosthenes code. In the second link I found a bit of code that run 10^7 in few seconds, with my old code to get a 10^8 with multi treading took few days! Shocked is the word I will used! Below is…

Read More Read More

Multi Threading and still looking for Primes

Multi Threading and still looking for Primes

Added some Multi Threading to my code to get full advantage of the dual core on my laptop: import threading import time import inspect import sqlite3 import math class Thread(threading.Thread): def __init__(self, t, *args): threading.Thread.__init__(self, target=t, args=args) self.start() # global variables count = 0 lock = threading.Lock() primeList = [] dbname=’/home/roberto/primelist.db’ table_name = ‘primes’ # name of the table to be created new_field = ‘prime’ # name of the column field_type = ‘INTEGER’ # column data type def createDB(): #…

Read More Read More

Prime number 2. The sqlite strikes back!

Prime number 2. The sqlite strikes back!

Finally got some code working with saving the Primes on a DB. I started by saving as I find the prime and realised that the constant IO activity was slowing the all process down. Next step was multi treading: this is still not 100%. Here is the code so far: # Python program to calculate prime numbers import math import threading import sqlite3 count = 0 primeList = [] dbname=’/home/roberto/primelist.db’ table_name = ‘primes’ # name of the table to be…

Read More Read More

How to find BIG prime numbers

How to find BIG prime numbers

If my calculations are right the best way to find a BIG prime number is to iterate through all the prime numbers before it, why? Because the quickest way to check a prime is to see if it is divisible by all the previous primes, I am not going to waste any processing power on non prime can be defined with prime numbers like 63 = 7*3^2. So here is my first attempt to find that BIG prime. (With BIG…

Read More Read More