Thursday, April 9, 2020

Deploying smart contracts to ganache using python and web3

Ganache is a useful tool that emulates Ethereum blockchain in your local machine and it is very practical for testing smart contracts. Most tutorials explain how to deploy a smart contract in ganache using truffle, which is a development framework by the same company. But this is not necessary. Here, I explain how to write and compile a contract using Remix, and deploy it using python and web3.py.

Write your smart contract in remix and compile it. Then press the "ABI" button on the bottom left (see picture) and paste the output in a file. This will be our ABI_file. Do the same with the "Bytecode" bottom. This will be the bin_file. Then you can use the python script from this github repository. Make sure you have installed the dependencies and that you have modified the ABI_file and bin_file variables of the script accordingly.




Sunday, May 19, 2019

CoAP POST using libcoap

View a list of all libcoap examples here.

This example includes a CoAP server and a CoAP client. 
The client performs a CoAP POST request for the "coap://127.0.0.1/hello" resource. The server listens on port 5683 (default port) and prints the POSTed data

You can find the source code of this example, as well as, instructions for compiling it in Linux in this github repository, in the "post" folder.

Friday, November 25, 2016

A CoAP server for the riot operating system using libcoap

View a list of all libcoap examples here.

The riot operating system (https://riot-os.org/) is an operating system for the Internet of Things that currently supports many platforms. One of the main advantages of riot is that it supports programs and libraries written in C including libcoap.

In this github repository you will find an example of a CoAP server for the riot operating system https://github.com/nikosft/libcoap/tree/master/riot This server implements a default resource that outputs "Hello World!".In order to test the example, download the latest version of the rios os (https://github.com/RIOT-OS/RIOT), create a folder inside the examples directory and copy the code from https://github.com/nikosft/libcoap/tree/master/riot in that new directory. Then from a terminal type
$ make

If you encounter any problem, consult this riot wiki page https://github.com/RIOT-OS/RIOT/wiki/Family:-native In order to use the example you have to create a virtual interface in your linux machine. In order to do this invoke the following utility:
$ <riot directory>/dist/tools/tapsetup/tapsetup -c1

This utility will create a virtural interface and a bridge (for more information visit this wiki page https://github.com/RIOT-OS/RIOT/wiki/Virtual-riot-network). After this step, from the folder where you have put the example code invoke:
$ make term

This command will execute the binary created in the previous step and soon an ipv6 address will appear in the terminal. You can now access the coap server using the libcoap coap client and the displayed ipv6 address, by invoking the following command:
$ coap-client coap://[<ipv6 address>%tapbr0]

Tuesday, September 6, 2016

Asynchronous CoAP request-response using libcoap

View a list of all libcoap examples here.

This is an example of asynchronous request-response. The server listens on port 5683 (default port). When it receives a request for the "hello" resource, it sends and ACK and after 2 seconds it responds with a "Hello World!".

The client performs a CoAP GET request for the "coap://127.0.0.1/hello" resource and prints the response.

You can find the source code of this example, as well as, instructions for compiling it in Linux in this github repository, in the "seperate" folder.

Sunday, July 17, 2016

libcoap examples

libcoap is an open source C implementation of the CoAP protocol. It can be used for developing CoAP services in Linux, MacOS, as well as, in various IoT operating systems such as Contiki, LwIP, and TinyOS.

However, libcoap lacks  documentation. Apart from some installation instructions there is not any tutorial on how to use the library. Moreover, the examples included in the source code are very complex and they cause confusion. I have constructed a small set of examples that use libcoap to perform simple tasks.

All examples are available on github

List of examples




Tuesday, March 29, 2016

Share a host folder with an Ubuntu VM using VirtualBox

This post describes how an Ubuntu based virtual machine on VirtualBox can access a windows folder.

In order to achieve this functionality follow the next steps.

Step 1. Run VirtualBox Manager, right click on your VM and select settings. There select the "Shared Folders" Option and press the add button on the right. In the "Folder Path" select the folder that you want to share, and in the "Folder Name" type a name. Moreover, select "Auto-mount" and "Make Permanent".

 

Step 2. Run your VM. Your folder has been mounted in the directory /media named "sf_<Folder Name>", where <Folder Name> is the name you selected in step 1. Nevertheless, this folder cannot be accessed.

Step 3. In order to be able to access the shared folder from your VM you have to add you user account to the group "vboxsf". You can do that by executing the following command:

sudo usermod -a -G vboxsf <username> 

Where <username> is your account user name. Restart, and you will be able to access the shared folder.

Tuesday, November 24, 2015

A Hello World CoAP client-server using libcoap

View a list of all libcoap examples here.

This is a simple example of a CoAP server and a CoAP client. The server listens on port 5683 (default port) and responds with a "Hello World!" to every request for the "hello" resource. The response is piggybacked in the ACK message.

The client performs a CoAP GET request for the "coap://127.0.0.1/hello" resource and prints the response.

You can find the source code of this example, as well as, instructions for compiling it in Linux in this github repository, in the "piggybacked" folder.