Using SHA1 to check data integrity

To test the integrity of data files often cryptographic Hash algorithms are used. NodeMCU offers several hash algorithms:

  • MD5
  • SHA1
  • MD2 (not available by default, has to be explicitly enabled in user_config.h)
  • SHA256, SHA384, SHA512 (unless disabled in user_config.h)

Default available are the common used algorithms MD5 (Message-Digest Algorithm 5) and SHA1 (Secure Hash Algorithm 1). Both algorithms compute a 128-bit respectively 160-bit hash value (check sum) from arbitrary files.
A common use of these algorithms can be found during file download from a file server over the Internet. The checksum of the original file is provided on the server, and after downloading, the concerned checksum will be calculated again and compared. If the checksums are identical, then the down loaded file is intact and the download was successful.

The program sample crypto.lua calculates the SHA1 checksum from the file credentials.lua which contains sensitive data as user passwords etc. This checksum and the corresponding filename will be saved in a file credentials.sha1, which can be used to compare calculated and saved checksums. The screenshot shows the call of the program sample and its output.

crypto

The program sample crypto.lua is available for download at sourceforge.net.

 

Using SHA1 to check data integrity

Weather Data from OpenWeatherMap

To get local weather information you do not need an own weather station. There are a lot of web-based weather stations collecting weather data from local weather stations around the world. To get an overview look for Top 10 Weather APIs.

If you want to use their weather data you have to consider the limited ressources of the ESP8266/NodeMCU devices. It is not possible to operate payloads of a few Kilobytes . The TCP/IP stack has its limitations.

I tried Yahoo Weather and Weather Underground but their responses were to big in size. After looking around I found openweathermap.org which offers a lot of data but fitting with the ressources of  ESP8266.

If you want to use this information you have to register at openweathermap.org to get an API key. I will name it myAPPID here. A free account offers no more than 60 calls/min respectively no more than 50’000 calls/day. This is quite enough for a call every minute.

The following call will request the data for my location:

http://api.openweathermap.org/data/2.5/weather?q=Altendorf,CH&APPID=myAPPID.

The response looks like

{“coord”:{“lon”:8.83,”lat”:47.19},”weather”:[{“id”:804,”main”:”Clouds”,”description”:”overcast clouds”,”icon”:”04d”}],”base”:”cmc stations”,”main”:{“temp”:282.67,”pressure”:1029,”humidity”:81,”temp_min”:282.15,”temp_max”:283.15},”wind”:{“speed”:1.5,”deg”:140},”rain”:{“3h”:0.0175},”clouds”:{“all”:90},”dt”:1450273800,”sys”:{“type”:3,”id”:6007,”message”:0.004,”country”:”CH”,”sunrise”:1450249519,”sunset”:1450280128},”id”:2661776,”name”:”Altendorf”,”cod”:200}

The NodeMCU application has to call the server and has to evaluate the response sent from server back to the NodeMCU device. The NodeMCU (Lua) script getWeather.lua is saved at Sourceforge.

weather

After downloading the script getWeather.lua to the the NodeMCU device we will get weather data every minute.

Access data to the router and the API key myAPPID are saved in the file credentials.lua  called from init.lua to hide them.

 

Weather Data from OpenWeatherMap

Adafruit Feather HUZZAH with ESP8266 WiFi

HuzzahLiPoAt the Feather HUZZAH’s heart is an ESP-12 module. You can progam the microcontroller using the Arduino IDE for an easy-to-run Internet of Things core or using the NodeMCU firmware. Fast code download with 921600 and auto-reset before download are available.

To make it easy to use for portable projects, a connector for a 3.7V Lithium polymer batteries and built in battery charging are added. No battery is needed when powering over the micro USB connector. But, if you do have a battery, you can take it on the go as wearable for example, then plug in the USB to recharge.

Adafruit Feather HUZZAH with ESP8266 WiFi