Posts

Showing posts with the label IoT Tutorials

Constrained Application Protocol (CoAP) using Node JS

Image
Constrained Application Protocol using Node JS Constrained application protocol is shortly called as CoAP and its based on Request Response Model where a browser or application will be requesting for a resource from the server. The resource would be a sensor reading like temperature, humidity, heartbeat, etc.  For complete explanation of the source code and the demo please go through the video: CoAP can be developed with many programming or scripting languages like: Python Node JS Contiki OS In this article, I will be writing or explaining the source code of CoAP using Node JS and this can be demonstrated with a plugin name called Cu Plugin for Chrome Browser. There are many CoAP client available like coap, libcoap, etc in Linux OS and Cu Plugin being a easier and common approach for a client.  You can refer the complete This program first starts the CoAP Server and accept only the JSON format headers, else it will throw the error number '4.06'.  Based on the requ...

Conikit NG installation in Ubuntu 20.04

Image
Contiki NG Installation This post shows the contiki NG installation in Ubuntu 20.04 OS. The same instruction will work for Ubuntu 22.04 as well.  Requirements: OS - Ubuntu 20.04  Contiki NG OS -  https://github.com/contiki-ng/contiki-ng  Watch the video for complete installation instructions Step 1 : Install the basics  Login in to Ubuntu and open the terminal.  Give the following command and press enter  $  sudo apt install build-essential doxygen git curl wireshark python-serial srecord rlwrap autoconf automake libxmu-dev gcc-msp430 default-jdk ant openjdk-11-jdk Contiki NG Step 2: To install GCC for ARM controller Download the following file and unzip (decompress) it in the home folder (in my case it is /home/pradeepkumar)  https://launchpad.net/gcc-arm-embedded/5.0/5-2015-q4-major/+download/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 set the above in the PATH Environment. /home/pradeepkumar/.bashrc to open the above file usin...

MQTT using Node JS | Node JS Tutorial

Image
This post shows you Simple MQTT Application using Node JS. There are three parts of the application. For running any MQTT application, we need a  1. Broker (The broker can be anywhere in the Internet or cloud or a local machine)  2. Publisher (pub.js is the name of the file) 3. Subscriber (sub.js is the name of the file) Check the following video for complete instructions. In this example, we will be using a broker called https://www.hivemq.com To use the cloud broker ( mqtt://broker.hivemq.com) and connect the publisher and subscriber with a topic and a message. To install the Hive MQ software in your local machine (127.0.0.1) and run the same above code locally and make the connectivity between the pub-sub. We open two new .js files called pub.js (publisher) and sub.js (subscriber) in Visual Studio Code. To install the mqtt module in NodeJS, we use the command “ npm install mqtt ” in C:/ terminal.  We define our client as connecting to “mqtt://broker.hivemq.com”. We...

Virtual Sensor implementation in Contiki NG OS

Image
Native Temperature, Humidity and Pressure Sensor in Contiki NG  Implementation of Three sensors namely temperature, humidity and pressure sensor in contiki NG OS. We need four files namely Step 1: Create a Folder called temperature/ in the folder contiki-ng/examples/ and then copy paste the following four files to the above folder. // mytemp.h #ifndef MYTEMP_H #define MYTEMP_H struct Sensor {  char name[15];  float value; }; struct Sensor read_temperature(); struct Sensor read_humidity(); struct Sensor read_pressure(); #endif // mytemp.c #include "mytemp.h" #include <string.h> #include <stdlib.h> float random_value(float min, float max) {  float scale = rand() / (float) RAND_MAX;  return min + scale * (max - min); } struct Sensor read_temperature() {  struct Sensor temp;  strncpy(temp.name, "Temperature", 15);  temp.value = random_value(0, 35);  return temp; } struct Sensor read_humidity() {  struct Sensor humdidty;  str...

Counter Design in Contiki NG Operating System

Image
Counter Design in Contiki NG OS $] make TARGET=native Step 1 - Files needed  myowncounter.h, myowncounter.c and ngcounter.c Makefile. Inside the folder contiki-ng/examples/myowncounter Step 2:  //myowncounter.h #ifndef MYOWNCOUNTER_H #define MYOWNCOUNTER_H int next_round(int temp); #endif Step 3:  //myowncounter.c #include "myowncounter.h" int next_round(int temp) { if(temp>59) temp=1; else  temp++; return temp; } Step 4:  //ngcounter.c #include "contiki.h" #include "sys/etimer.h" #include "mycounter.h" #include <stdio.h> PROCESS(mycounter_process, "My Counter Process"); AUTOSTART_PROCESSES(&mycounter_process); static struct etimer et; static int count=0; PROCESS_THREAD(mycounter_process,ev,data) { PROCESS_BEGIN(); while(1) { etimer_set(&et, CLOCK_SECOND*2); PROCESS_WAIT_EVENT_UNTIL(etimer_Expired(&et)); count=next_round(count); printf("Count Value : %d\n",count); } PROCESS_END(); } Step 5: Mak...