Skip to main content

Posts

Showing posts from November, 2018

libesphttpd and Micro API

libesphttpd is a HTTP server library for ESP8266. It has a fair documentation on Github and a demo . It supports common gateway interface (CGI) in C. It also has a tool to compile a collection of web pages into a binary blob which is to be flashed into ESP8266 separately from the web server codes. It can host static web files. In general, libesphttpd can be used to build a complete web server for ESP8266. However, ESP8266 is too tiny for a full blown web server. It is a standard practice to separate the development of web pages and a web server. In fact, due to the limited resources of the ESP8266, the web server should be kept to minimum by only exposing APIs. The web pages should be designed as the applications that run at the client side. I wrote a micro-api framework using libesphttpd and esp-open-sdk . Separation of concerns is important in web application development since it involves multiple stacks of tools. On the server side there will be embedded C-based tools. And

Position of the Sun

I was working on the Prayer Times when I stumbled upon the notion of the position of the Sun  in Wikipedia. I was converting the Javascript codes into C and made a major restructuring of the codes so that I know what was the main contributor. It was the position of the Sun. All Muslim prayer times are related to solar events such as sunrise, noon and sunset. The details of the calculation of the position of the Sun are involved. The true relationship between the Earth and the Sun is never constant. The method that is given by Wikipedia is just an approximation which is good enough for few decades to come. Hopefully by that time we already have a better approximation. The events of sunrise to sunset are due to the Earth rotation on its polar axis. Never expect the Sun's circling the Earth to be in the perfect 24 hour rotation. The noon is never at the same time every day. This is due to the motion of the Earth orbiting the Sun. The orbit is not a perfect circle and the speed of

Git My Way

Update : This blog was written about two years before Github dropping the so-called divisive "master" terminology , and renamed it to "main". But I'm not going to change anything here. I just want to keep the original context as is. Please read master as main . After all this while I still could not remember how to do git right, and I kept on coming back to this blog, each and every time I wanted to update a Github repo. If you are careless then you may encounter "fatal: Couldn't find remote ref master", and Google will lead you into a pit of old and unrelated discussions. I used to bookmark a number of git tutorials. Most of it works but only to a certain extend until I forgot most of the required steps later. The steps were not intuitive and can easily be forgotten. Git uses alien English. Then I realize that I have to list my own way of using git. I believe all of you have too because we depend on it. I use git with Github and mostly to upda

Connecting to a Micro Web Server

ESP8266 can be programmed to serve a micro web server which can be accessed through WiFi. However, connecting to the module involves multiple steps. Connecting to a WiFi Access Point (AP) is like physically plugging-in a cable of a Local Area Network (LAN) into its switch. Yet it does not immediately connect our device to a web server. A connection to an AP may not necessarily get our device into an Internet Protocol (IP) network where a web server is hosted because a WiFi AP does not necessarily implement IP. Similarly, a LAN switch may not necessarily implement IP. At the very low level of networking the devices may identify each other through Media Access Control (MAC) addresses. A mesh networking implements a communication layer below IP. It is up to the devices to implement their own networking protocol. However, IP happens to be pervasive in WiFi networking. ESP8266 does implement IP and a Dynamic Host Configuration Protocol (DHCP) server which assign our device with a dynami