Subhra's Lab
Insights on different Embedded & Internet technologies like Android, Nodejs, Firebase, esp8266 etc. Projects like reading from and writing to google sheet using esp8266 devices, putting math symbols in your web sites, setting up your own wamp stack (each component separately) on your local pc, extracing hex code from unicode char code, developing firebase messaging system for your users android devices using nodejs server etc are described elaborately. More projects to come..
Friday, 2 May 2025
remote door bell
Wednesday, 30 April 2025
Remote motion sensor with LED bulb
Tuesday, 27 December 2022
Monday, 26 December 2022
Monday, 6 June 2022
Read and Write to Google Sheet from your ESP8266 device.
In this article we access our google sheet data
from our google drive with our ESP8266 device.
Google Sheet
Figure1
ESP8266
Esp8266 is a wifi module along with a microcontroller widely used in IOT (internet of things) technology. As the ESP devices has inbuilt microcontroller, this small device can be used as a small computer (without monitor and terminal) at any place at convenient. It just work silently. There are variants of these devices like ESP8266-01, ESP8266 Node MCU, ESP32 etc.
How ESP Devices Collects Data and Outputs Data:
An ESP device collects data through its sensors
connected to its pins and send it to the defined internet address. Similarly,
it collects data from the defined internet address and send it to its output
pins for actions.
Usages: case 1: Suppose, you have a display
unit. You want to display records collected from a remote location through
various meas like sensors and other input devices. Here you can use an ESP
device as the data collector and provider to your display unit.
Case 2: Say, you organized a conference. You
want to get the number of total members present at any time in the conference
hall from a remote place. You can deploy ESP8266 here to collect the data
through the sensors and send it your mobile device silently.
Case 3: Nowadays, Fastag has been introduced in
Indian National Roadways. It works through the RFID sensors at traffic gates.
The device modules at the gates get the data about the vehicle and do the toll
operations without stopping the vehicle any more. We can achieve this type of
performances also with these ESP devices.
Now, we will follow the steps below to connect
he google spreadsheets and do read/write operations on it.
STEP1: Bill of Materials:
(hardwares)
(i) An ESP8266 module device
(ii) An ESP8266 burner (if it is a node mcu,
burner is inbuilt)
[Note: burner device is required only for
ESP-01 devices, for others, we just need to connect the ESP Node MCU to the computer
USB Cables.]
(iii) A Personal Computer to prepare the
software and upload it to ESP
Software
(i) We will use Windows 10 to prepare &
upload it to ESP8266
[Note: Different versions of Arduino IDE are
available for different OS versions]
(ii) We need to install Arduino IDE for our
working environment.
STEP2:
(i) Download ReadSheetData zip library from this
link.ReadSheetData
(ii) Go to google Sheet. It you can get it in
your google.com page inside Google apps at the top right corner region.
Figure 2
Figure3
(III) create a spread sheet like below
Figure4
(iv) copy the spread sheet id from the url
address like below:
See the address bas: docs.google.com/spreasheet…
From here copy the part within ‘../d/’ and ‘/edit..’. This will be used as the
spreadsheet id in the app script.
(v) add another sheet clicking the bottom left (+) button. (we can toggle between sheets clicking the sheet1 and sheet2 tab).
Figure5
(vi) Go to tools>Script editor
(vii) Script editor will be opened in a new tab.
(viii) copy the contents MyAppScript.gs file
from the ReadSheetData.zip library and paste it here.https://github.com/subhramukherjee/ESP8266_Logger.git
(ix) Replace the spreadsheet id with that copied at point (iv) in step2.
Figure6
(ix)Now deploy your app script as a web app and
collect the ScriptID. Click Deploy>New
Deployment
Follow the following steps:
Figure7
Figure 8
Figure9
Now select Anyone in ‘Who has access’ drop-down list. Click Deploy. The system will ask for your authorization. Follow the subsequent steps. In the process following a security warning may come. Go ahead and give authorization (as you know, it is your app script & it is not going to case any harm to any system).
Figure10
We can now test our App Script in any web
browser. Just copy and paste the web address ( we get it on Manage Deployment
tab in the drop-down list we get by clicking Deploy button of the App Script
window) to the address bar of any web browser.
Remember: Whenever we make any
change to our app script and again go to deploy our app, we must select ‘New
Deployment’ from the list.
After all are done, we will get the following window:
Now copy the Google App ScriptID to your
secure space. This ID will be required in our ESP8266 code.
Now, Google Script setup is over. Follow the
net step.
STEP3:
(i) Download HTTPSRedirect zip library from
Github (You can download the ConnectSheet.zip file from this link also, unzip
it). Now open the Arduino IDE. Go to Sketch>Include Library>Add .ZIP
Library…
Here select the HTTPSRedirect.zip file, the
HTTPSRedirect library will added to your library list in Sketch>Include
Library.
You can import it as a header file in your .ino
code file.
(ii) You can also download the ReadSheetData.zip
from the following github resource. https://github.com/subhramukherjee/ESP8266_Logger.git
(ii). Click File>Open. Get the ReadSheetData.ino
by unzipping the ConnectSheet.zip file you just downloaded.
(iii) Replace the ssid and password with your
wifi ssid and password.
(iv) Replace the GScriptId value with the
ScriptID you just collected when deploying your Google AppScript.
(v) Do any necessary changes as per your need.
(vi) upload the .ino file to your ESP8266.
(vii) Go to Tools>Serial Monitor
We will see that the spread sheet data is being
displayed on the serial monitor of Arduino IDE.
You can use these data in many purposes like
operating other devices, display units etc. We can also send valuable data
collected through sensors to the Google sheet.
To write to the google sheet input some text in
the Serial input bar. And wait. You will see that your input has been inserted
in the Google sheet.
Sunday, 22 May 2022
EXTRACT
ONE BYTE HEX CODE FROM UTF-8 BYTES REPRESENTING A UNICODE CHARACTER (UTF-8
TRICKS)
[This
article assumes the reader knows the hexadecimal number system]
What is
UTF8?
Multilingual
characters are indexed in a table having each a 16 bit address. This is Unicode
table. Thus, using two bytes (each having 8 bits) we could represent any
character other than English. But as the English characters are represented in
a single byte, we need an encoding which is universal for supporting all the
scripts accepted worldwide. More over after addition of more charsets from
scripts in different parts of the world (as extended Unicode, in a vow to
include all the character and symbols around the globe), the 16 bits became
insufficient for Unicode. The UTF-8 brought the solution. Utf-8 is such an encoding
system which gives us this privilege to represent any character used anywhere
within same common encoding system.
The utf-8 encoding system needs one to four
bytes in a stream to represent a character or a symbol.
The Utf-8
byte sequences follow a definite unique pattern. The pattern is used to
validate the correct utf8 sequence. Below is the demonstration of the utf8
pattern:
Single
Byte UTF-8
For single
byte utf-8 encoding, used pattern is:0xxxxxxx (7 bits are used)
Thus it can
represent 00000000 to 01111111 i.e.
Unicode U+0000 to U+007F. So, these are sufficient to express English
characters.
Two Byte
UTF-8
For 2 byte
utf-8 encoding, used pattern is: 110xxxxx 10xxxxxx. (Here, 5 + 6 = 11 bits are
used)
Thus, it can
represent U+0080 to U+07FF. This is used for scripts like Greek, Arabic etc.
Three
Byte UTF-8
For 3 byte
utf-8 encoding, used pattern is: 1110xxxx 10xxxxxx 10xxxxxx. Thus it uses total
4 + 6 + 6 = 16 bits. Thus, we can represent U+0800 to U+FFFF. This is used for
scripts like Devanagari, Bengali, Gurumukhi and others Indic language script
characters falls in this range.
After this
we need more than 16 bits to represent extended Unicode characters.
Four Byte
UTF-8
For 4 byte
UTF-8 encoding, used pattern is: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx. Thus, it
uses a total of 21 bits (3 + 6 + 6 + 6). Thus, it can represent from U+10000 to
U+10FFFF.
This unique
pattern of utf8 encoding system is required to validate the true utf8 sequence.
Example
Decode
In the
following example we will extract a single byte hex code from a three byte utf8
stream. The hex code will be unique within the Unicode range used for that
script.
The utf-8
sequence for Bengali ী is E0 A7 80 and the position of ী in Unicode table is U+09C0.
Now, utf-8
pattern for Bengali characters(3 bytes sequence) is :1110 xxxx - 10xx xxxx - 10xx xxxx.
Now, 1st
byte is E0; thus, in this case 1st byte becomes 1110 0000
The 2nd
byte is A7, thus it becomes, 1010 0111
The 3rd
byte is 80, thus it becomes, 1000 0000
Thus, the
whole bit sequence for ী becomes 0000 1001 – 1100 0000 (if we
extract pattern identification bits). Thus, converting to HEX, it becomes
U+09C0 as per the Unicode table.
Now, we will
do the same through coding:
For this, we made the third byte as
the base, replaced its the leading 10 with the last two bits from the middle
byte. The rest leading bits will always form a 9 which is not required for this
range of Unicode characters.
. uint8_t a[3];
. a[0]
= 0xE0;
. a[1]
= 0xA7;
. a[2]
= 0x80; [utf8 sequence for ী ]
. uint8_t
x = a[1]&0x03; [we take
last 2 bits only]
. x
= x<<6; [shift
bits by 6 steps left]
. uint8_t
y = a[2]&0x3F; [resets the
left most 2 bits to 0]
. y
= x|y;
This is 0xC0 which is the hex code of ী ,
unique up to the required range.