Irak MayerStephanie Vicarte
Published © MIT

Smart Rider

Smart Rider allows the user to verify the identity of your ride before boarding the vehicle. Smart safety with IOTA.

IntermediateFull instructions providedOver 2 days346
Smart Rider

Things used in this project

Hardware components

Adafruit HUZZA32 ESP32
×1
Adafruit TFT FeatherWing - 2.4" 320x240 Touchscreen For All Feathers
×1
Cellphone Samsung S7 Edge
×1

Software apps and online services

JAVA
JavaScript
ESP32 IDF
C language
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Smart Rider with IOTA

Smart Rider with IOTA schematic

Code

IOTAWindow.java

Java
Main program for user interface and to call the IOTA libraries.
package MyWinIOTA;


import java.awt.EventQueue;

import javax.swing.JFrame;
import org.iota.jota.dto.response.SendTransferResponse;
import org.iota.jota.error.ArgumentException;
import org.iota.jota.model.Transaction;
import org.iota.jota.model.Transfer;

import com.google.gson.Gson;

import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.util.List;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

public class IOTAWindow {

	private JFrame frame;
	private JTextField passcodeTxt;
	private JTextArea statusField;

	public void prepareMessage() {
		SendTransferResponse retTransfer;
		String data;
		List<String> retResponse;
		
		SendMessageTest MyMessage = new SendMessageTest();
		
		MyMessage.createApiClientInstance();
		
		retTransfer = MyMessage.shouldSendMessage(passcodeTxt.getText());
		
		data = retTransfer.getTransactions().get(0).getSignatureFragments().substring(0, 20);
		data = data + " \n" + retTransfer.getTransactions().get(1).getSignatureFragments().substring(0, 20);
		statusField.setText(data);

		retResponse = MyMessage.shouldGetTransfers();
		
        for (String strData : retResponse) {
        	data = data +"\n" + strData.substring(0, 20);
        }
        statusField.setText(data);
        
        JOptionPane.showMessageDialog(frame, "Done");
		
	}
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					IOTAWindow window = new IOTAWindow();
					window.frame.setVisible(true);
					
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public IOTAWindow() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 430);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JButton btnSendPasscode = new JButton("Send Passcode");
		btnSendPasscode.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				prepareMessage();
				//JOptionPane.showMessageDialog(frame, "Button Pressed");
			}
		});
		btnSendPasscode.setBounds(128, 125, 157, 25);
		frame.getContentPane().add(btnSendPasscode);
		
		passcodeTxt = new JTextField();
		passcodeTxt.setBounds(58, 69, 333, 44);
		frame.getContentPane().add(passcodeTxt);
		passcodeTxt.setColumns(10);
		
		JLabel lblEnterPasscode = new JLabel("Enter passcode");
		lblEnterPasscode.setBounds(58, 42, 115, 15);
		frame.getContentPane().add(lblEnterPasscode);
		
		JLabel lblStatus = new JLabel("Status");
		lblStatus.setBounds(30, 173, 70, 15);
		frame.getContentPane().add(lblStatus);
		
		statusField = new JTextArea();
		statusField.setLineWrap(true);
		statusField.setWrapStyleWord(true);
		statusField.setEditable(false);
		statusField.setBounds(28, 200, 394, 172);
		frame.getContentPane().add(statusField);
		statusField.setColumns(10);
	}
}

SendMessageTest.java

Java
Class to connect and send message thru IOTA development tangle.
package MyWinIOTA;


import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.iota.jota.IotaAPI;
import org.iota.jota.dto.response.GetTransferResponse;
import org.iota.jota.dto.response.SendTransferResponse;
import org.iota.jota.error.ArgumentException;
import org.iota.jota.model.Transaction;
import org.iota.jota.model.Transfer;
import com.google.gson.Gson;
import org.iota.jota.model.Bundle;


public class SendMessageTest {

    private static final String TEST_SEED1 = "IHDEENZYITYVYSPKAURUZAQKGVJEREFDJMYTANNXXGPZ9GJWTEOJJ9IPMXOGZNQLSNMFDSQOTZAEETUEA";
    private static final String TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2 = "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZCCOZVXMTXC";
    private static String TEST_MESSAGE = "JUSTANOTHERJOTATEST";
    private static final String TEST_TAG = "MYSPSPAM9999999999999999999";
    private static final int MIN_WEIGHT_MAGNITUDE = 14;
    private static final int DEPTH = 4;//9;

    private IotaAPI iotaClient;

    public void createApiClientInstance() {
    	iotaClient = new IotaAPI.Builder()
    	        .protocol("https")
    	        .host("nodes.devnet.thetangle.org")
    	        .port(443)
    	        .build();    	
    }

    public List<String> shouldGetTransfers() throws ArgumentException {
    	List<String> retData = new ArrayList<>();
    	int index=0;
    	
        GetTransferResponse gtr = iotaClient.getTransfers(TEST_SEED1, 2, 0, 0, false);
        gtr.getTransfers();

        for (Bundle test : gtr.getTransfers()) {
            for (Transaction trx : test.getTransactions()) {
            	retData.add(trx.getSignatureFragments());
                System.out.println(retData.get(index++));
            }
        }
        
        return retData;
    }
    public SendTransferResponse shouldSendMessage(String txtMessage) throws ArgumentException {
        List<Transfer> transfers = new ArrayList<>();
        List<Transaction> tips = new ArrayList<>();

        TEST_MESSAGE = txtMessage.replaceAll("\\s", "").toUpperCase();
        
        // for each 2187 trytes in a message one transfer is necessary
        transfers.add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2, 0, StringUtils.rightPad(TEST_MESSAGE, 2188, '9'), TEST_TAG));

        SendTransferResponse str = iotaClient.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false, false, tips);
        str.getTransactions();
        str.getTransactions();
        str.getSuccessfully();
        
        return str;
    }
}

QR code generator for arduino

Arduino
Notice that we update the display to use the ILI9341 using the GFX library from Adafruit. We are currently trying to use the ESP32_TFT_Library.
/* *********************************************************************************
 * ESP8266 QRcode
 * dependency library :
 *   ESP8266 Oled Driver for SSD1306 display by Daniel Eichborn, Fabrice Weinberg
 *
 * SDA --> D6
 * SCL --> D7
***********************************************************************************/

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

#include <esp32qrcode.h>

   #define STMPE_CS 32
   #define TFT_CS   15
   #define TFT_DC   33
   #define SD_CS    14

Adafruit_ILI9341 display = Adafruit_ILI9341(TFT_CS, TFT_DC);
ESP32QRcode qrcode (&display);

void setup() {

    Serial.begin(115200);
    Serial.println("");
    Serial.println("Starting...");

    display.begin();

    // Initialize QRcode display using library
    qrcode.init();
    // create qrcode
    qrcode.create("UNIQUECODEBLUE");

}

void loop() { }

esp32qrcode.cpp

Arduino
Modified qrcode library to use the ILI9341
#include <Arduino.h>
#include "esp32qrcode.h"
#include "qrencode.h"

int offsetsX = 42;
int offsetsY = 10;
int screenwidth = 320;
int screenheight = 240;
bool QRDEBUG = false;

ESP32QRcode::ESP32QRcode(Adafruit_ILI9341 *display){
	this->display = display;
}

void ESP32QRcode::init(){
	if(QRDEBUG)
		Serial.println("QRcode init");

  display->begin();
  //display->flipScreenVertically();
  display->fillScreen(ILI9341_BLACK);
}

void ESP32QRcode::debug(){
	QRDEBUG = true;
}

void ESP32QRcode::render(int x, int y, int color){
  x=x+offsetsX;
  y=y+offsetsY;
  if(color==1) {
    display->drawPixel(x*2,y*2,ILI9341_BLACK);
    display->drawPixel((x*2)+1,(y*2)+1,ILI9341_BLACK);
    display->drawPixel((x*2),(y*2)+1,ILI9341_BLACK);
    display->drawPixel((x*2)+1,(y*2),ILI9341_BLACK);
  }
  else {
    display->drawPixel(x*2,y*2,ILI9341_WHITE);
  }
}

void ESP32QRcode::screenwhite(){
  display->fillScreen(ILI9341_WHITE);
}

void ESP32QRcode::create(String message) {

  // create QR code
  message.toCharArray((char *)strinbuf,260);
  qrencode();
  screenwhite();

  if(QRDEBUG){
	Serial.println("QRcode render");
	Serial.println();
  }
  // print QR Code
  for (byte x = 0; x < WD; x+=2) {
    for (byte y = 0; y < WD; y++) {
      if ( QRBIT(x,y) &&  QRBIT((x+1),y)) {
        // black square on top of black square
        if(QRDEBUG)
			Serial.print("@");
        render(x, y, 1);
        render((x+1), y, 1);
      }
      if (!QRBIT(x,y) &&  QRBIT((x+1),y)) {
        // white square on top of black square
        if(QRDEBUG)
			Serial.print(" ");
        render(x, y, 0);
        render((x+1), y, 1);
      }
      if ( QRBIT(x,y) && !QRBIT((x+1),y)) {
        // black square on top of white square
        if(QRDEBUG)
			Serial.print("@");
        render(x, y, 1);
        render((x+1), y, 0);
      }
      if (!QRBIT(x,y) && !QRBIT((x+1),y)) {
        // white square on top of white square
        if(QRDEBUG)
			Serial.print(" ");
        render(x, y, 0);
        render((x+1), y, 0);
      }
    }
    Serial.println();
  }
  Serial.println();
  //display->display();
}

esp32qrcode.h

Arduino
Header file for modified qrcode library
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

class ESP32QRcode
{
	private:
		Adafruit_ILI9341 *display;
		void render(int x, int y, int color);

	public:
		ESP32QRcode(Adafruit_ILI9341 *display);

		void init();
		void debug();
		void screenwhite();
		void create(String message);
};

Credits

Irak Mayer

Irak Mayer

8 projects • 5 followers
Stephanie Vicarte

Stephanie Vicarte

8 projects • 6 followers

Comments