Published 6 November 2018

Using CREDITS API and Open IoT Stack for Java

Using CREDITS API and Open IoT Stack for Java

To use the functionality provided by the CREDITS platform, it is necessary to know and understand the API provided by the platform and Open IoT Stack for Java in the development of the Internet of things.

Open IoT Stack for Java (developed by Eclipse Foundation) - software development platform for consumer and corporate Internet of things.

Open IoT Stack for Java supports a group of communication standards between devices and offers ready-made libraries to create IoT gateways, home automation systems, and SCADA industrial systems.

The platform contains the following:

  • Paho - Java-client, implementing protocol of MQTT intermachine communication;
  • Moquette - broker of MQTT messages;
  • Coap - non-resource-intensive IETF protocol for transmitting information over the Internet;
  • Leshan - Java-Implementation of Lightweight M2M, a lightweight management interface between clients and IoT servers, proposed by Open Mobile Alliance.

Necessary steps to start the development:

  1. Purchase hardware, such as (http://www.raspberrypi.org/) Raspberry Pi and start experimenting.
  2. Learn the guide https://iot.eclipse.org/java/tutorial/ (build a smart greenhouse).
  3. IoT standards, MQTT and CoAP. Eclipse Paho and Californium provide implementations of each.
  4. For the home automation DIY, learn about (https://www.eclipse.org/smarthome/) Eclipse SmartHome , a Java based framework for home automation.
  5. Discover the developer resources available at different sites, like iot.eclipse.org and java.net
  6. Learning CREDITS API

Implementation of CREDITS software

Implementation of CREDITS software

The CREDITS company provides and recommends using API for use in existing solutions.

Since tokens are written in the Java language, the introduction of CREDITS functionality into solutions on Open IoT Stack for Java don't seem complicated due to the use of a single Java programming language.

Next, you must use an existing token or create a new one on the CREDITS platform. Two Java interfaces are provided as standard:

  • BasicStandard (implementation required by the standard)
  • ExtensionStandard (implementation recommended by the standard)

A prerequisite for the operation is to run the following Java application from the standard CREDITS delivery (port 9080 should not be busy):

start call java -jar contract-executor.jar

Below is the wallet balance request code, via CREDITS API (the code can be invoked if there is a Java virtual machine installed):

import com.credits.common.exception.CreditsCommonException;

import com.credits.common.utils.Converter;

import com.credits.leveldb.client.ApiClient;

import com.credits.leveldb.client.exception.CreditsNodeException;

import com.credits.leveldb.client.exception.LevelDbClientException;

import java.math.BigDecimal;

public class app {

   public static void main(String[] args) throws CreditsCommonException, LevelDbClientException, CreditsNodeException {

       String account = "6zxLh3nbbtxt36ED211Y3askbbSY4E1iV98TKcFzjoUk";

       ApiClient client = ApiClient.getInstance("127.0.0.1", 9090);

       BigDecimal balance = client.getBalance(Converter.decodeFromBASE58(account), (byte)1);

       System.out.print(balance);

   }

}

0 Useful article

Contents