Project showcase
Windows 10 IoT Core : Hydroflyer

Windows 10 IoT Core : Hydroflyer © GPL3+

Modify RC boat and maneuver using Windows Phone or Window Laptop.

  • 18,178 views
  • 3 comments
  • 57 respects

Components and supplies

RC Boat (Min 48 cm long)
×1
R8326274 01
Raspberry Pi 2 Model B
×1
Ard nano
Arduino Nano R3
×1
Esp01
Espressif ESP8266 ESP-01
×1
GPS Module (uBlox Neo 6m; 9600 baud)
×1
Digital Compass HMC5883L
×1
N-Channel MOSFET (75NF75)
×1
L298 (H-Bridge Motor Driver)
×1
Voltage Regulator 3.3V (LD1117V33)
×1
Voltage Regulator 5V (7805)
×1
Electrolytic Capasitor (35V; 100uF)
×6
Glass Fuse (5 Amp)
×1
Glass Fuse (10 - 15 Amp)
×1
Resistor 1K
×2
Resistor 2K
×1
Diode (1N5822)
×1

Apps and online services

About this project

Playing with a radio controlled toy is much fun. When is comes to water vehicle, we love them maneuvering whole day. If you are passionate for Windows and are a good hacker, this article is for you.

This article reveal the technique to modify RC Boat that will be controlled using Windows Phone. In addition, the source code contains libraries to develop application for Windows based OS, too.

 

Whats new in this article?

Arduino Wiring Project for Windows IoT Core

Microsoft has released awesome features to the Windows IoT build 10.0.10556 (Insider Preview). With this build, now you can write Arduino sketch for Windows IoT Core directly from Visual Studio 2015 (Refer this article for more information).

Overcome Existing Limitation of Windows IoT Core (Serial-UART, PWM)

RPi2 supports for PWM and UART on board but current release of Windows IoT Core (10.0.10556) doesn't. Regarding to this project, we need PWM to control motor speed and serial (UART) for ESP8266-01 and GPS.

As per Windows IoT Release notes, ADC and PWM is supported via external chips but I'm not sure about the availability of that chips in all regions. While Arduino is widely available worldwide. So why not to chose Arduino. In addtion, it is a full-fledged microcontroller having its own benefits.


Essential

Before going further, you must need following:

  1. Your Raspberry Pi 2 must have latest Windows IoT Core Insider Preview. (Download) (How to install Windows IoT Core on RPi2?)
  2. Raspberry Pi 2 must be setup for Lightning feature. (Lightning Setup)
  3. You must install latest Windows IoT Core Project Template. (Download)
Lightning is a set of providers to interface with GPIO, I2C and SPI through the lightning Direct Memory Access driver. In short, it is the new driver which provides high performance against default inbox drive by accessing direct memory mapped driver. By default Windows IoT Core is configured for default inbox driver.


Basic Concept

Raspberry Pi 2 (running Windows 10 IoT Core), will communicates with Windows device via Communication Link. Windows IoT Core will takes appropriate maneuver signal from remote Windows device and generates the appropriate signal to control engine and rudder (if available). In addition, Windows IoT running on RPi2 will send back sensor data to the remote Windows device to process it and show.

Let's see which communication & sensor module to be used:

Each boat have different hardware configuration to maneuver it. Let's explore three basic configuration mode:

The source code for the project is only developed for Mode 2. With minor changes you can program for Mode 1 as well as 3 if you really understood the concept of Gateway.


Gateway (for ADC, PWM & Serial Communication)

With the release of Windows IoT build 10531, ADC and PWM are supported via external chips. That means there is no direct support for on-board pins. Even, on-board Serial Port is useless because it may be used by kernel debugger.

In this project, WiFi (ESP8266) and GPS module (uBlox Neo6mV2) uses Serial Communication (UART). PWM is going to be used for motor speed control as well as to control servo for configuration mode 3. Thus some extra components will be required to accomplish goal. Arduino Nano or Arduino Pro Mini (16MHz) will be used to provide Serial Port as well as PWM signals. It will work as gateway:

Now, Windows IoT can access to ADC, PWM and Serial devices via gateway. To access any peripheral connected to the gateway device, it just need to access gateway chip via I2C bus.

If major peripherals are connected to the gateway (Arduino), then what will be the responsibility of Raspberry Pi 2 and Windows IoT?>Raspberry Pi and Windows IoT can be called the brain. It gets data via ESP8266, process them and controls the peripheral via gateway. Arduino is limited to its memory and processing power, thus its not capable to deliver real-time application. For ex: The real power comes when you wanna use Windows IoT for video processing, sound processing, autonomous system, etc.

Let's explore gateway programming:

You don't need to modify ESP8266-01 and Gateway sketch. You just need to upload it. Once you have uploaded, it will work like charm. You just have to code for Windows IoT.


Sketches

This project is a bit complicated. Thus the code is divided into three parts:

  1. ESP8266 Sketch
  2. Gateway Sketch
  3. Windows IoT Sketch


Main objective of ESP8266 Sketch is to create Access Point and listen for incoming GET request. Request will be consists of arguments that must be placed into global argument buffer. Once arguments are copied, respond back with plain text which consists of data sent from Windows IoT via Gateway. Thus ESP8266 Sketch is responsible to communicate with remote device.

Gateway Sketch provides ADC, PWM and Serial service to Windows IoT on demand. It is also responsible to exchange data with ESP (using UART) as well as Windows IoT sketch via I2C.

Windows IoT Sketch is the brain. You can use it for complex processing such as autonomous guidance system. Windows IoT Sketch can get arguments that are passed by remote device to ESP8266 on demand. It can also send string to the remote device using ESP8266 via Gateway.

The following diagram will helps you to better understand how data is exchanged:


Deploy

ESP8266-01 Sketch

To flash or reprogram ESP8266-01, you need to wire-up ESP8266-01 as shwon below:

Once you are done with wiring, open Arduino IDE and follow:


Gateway Sketch (Arduino Nano)

Upload the Gateway sketch to the Arduino Nano. Gateway sketch is provided at the end of the article.


Windows IoT Sketch

Deploy 'ArduinoWiringWIoT' to your RPi2.

After successful deployment, we need to register this app as startup app. You can register as startup app in two way:

  1. Web management portal
  2. PowerShell

But due to bug in current release of Insider Preview (10.0.10556), web management portal won't works at this time and don't try to register using web management portal because RPI2 won't boot up after reboot. And finally you will have to re-flash your Windows IoT.

So let's register using PowerShell:

  1. Log-in to your RPi2 using PowerShell (refer this article)
  2. Type: IotStartup remove and hit enter
  3. Find the application you have deployed to your RPi2 using: IotStartup list
  4. Add your application to startup application: IotStartup add headless <your-app-package-name>
  5. Now, set Windows IoT to boot in headless mode: setbootoption headless
  6. Finally, you need to restart Windows IoT in order to save changes: shutdown /r /t 0


Voila, you have just deployed all of the three sketched to your ESP, Gateway and RPi2. Now its time to wire up things. Refer the following schematic to wire-up:


At The End

Deploy the application provided for Windows Phone 8.1/10. Connect them all the go, connect Windows Phone to the ESP8266 AP, start WP Dashboard app and enjoy :)


Known Issues

Windows IoT Project : Arduino Wiring (Naming Issue)

Do not use space or any special symbol when creating Arduino Wiring project for Windows IoT. It will generate compile time error like:

Compass (HMC5883L) Jitter

HMC5883L is much sensitive to the electromagnetic waves. Thus you must need to place it as far as away from such electromagnetic emitting device like motors, communication modules, etc.


Windows Phone Application won't start

In order to run provided WP application, your phone must have built-in GPS. If your phone does not have built-in GPS, you can disable code block that retrieves the WP's location.


Conclusion

Day by day Windows IoT team is providing rich set of new features. With the current release 10.0.10556, a new driver "Direct Memory Mapped" is integrated which is far better than the Inbox driver. Performance is also significant improved over the old one. By combining other microcontrollers, we can overcome limitation of the Windows IoT or Raspberry Pi 2 as I have given concept of Gateway which serves ADC, PWM and Serial to the RPi2. In addition, such gateway can be called as co-processor because it saves a lot of time of the RPi2 by doing some task for it and interrupts the RPi2 when task completed.

Code

ESP8266-01 (Arduino Sketch)C/C++
/*
	ESP8266-01 sketch for Hydroflyer (Boat) (RPi2 + WinIoT)
	https://www.hackster.io/AnuragVasanwala/windows-10-iot-core-hydroflyer-f83190

	NOTE: This sketch is tested and meant for ESP8266-01.

	Objectives:
	+ Create Access Point (Act as WiFi)
	+ Listen for 'Maneuver' GET requests
	+ Fetch arguments from GET request and store them in global 'Arguments'
	+ Respond back plain-text from global buffer 'ReplyBuffer_100' which was received from gateway
	+ On root or index GET request, send back project description html page
	+ Initialize serial port and listen for incoming data
	+ When data is received from gateway and send it back global 'Arguments'
	+ Gateway will send character array to ESP which will be store in global buffer 'ReplyBuffer_100'
	+ ESP will send back character array 'ReplyBuffer_100' to requested remote device via 'Maneuver' GET request
	+ Auto-reset global Arguments if no device connects for more than 'AutoReset_Timeout'

	: WARNING :
		+ 'Argument_Size' AND 'SensorBuffer_Size' MUST BE IDENTICAL ON GATEWAY SKETCH.
		+ SERIAL BAUD RATE MUST BE SAME ON BOTH SIDE (GATEWAY & ESP).
		+ 'SEND_DATA_STRUCTURE' MUST BE IDENTICAL ON GATEWAY SIDE (WITH NAME OF 'RECEIVE_DATA_STRUCTURE').
		+ 'RECEIVE_DATA_STRUCTURE' MUST BE IDENTICAL ON GATEWAY SIDE (WITH NAME OF 'SEND_DATA_STRUCTURE').
		+ YOU MUST HAVE 'EasyTransfer' LIBRARY IN YOUR ARDUINO FOLDER.
		  TO INSTALL 'EasyTransfer', REFER: https://github.com/madsci1016/Arduino-EasyTransfer
		  THIS REPOSITORY CONTAINS:
			  + EasyTransfer
			  + EasyTransferI2C
			  + EasyTransferVirtualWire
			  + SoftEasyTransfer

			  BUT YOU ONLY HAVE TO COPY FIRST FOLDER 'EasyTransfer' TO YOUR ARDUINO's LIBRARY FOLDER
*/

/* Global Includes */
#include <ESP8266WiFi.h>
#include <EasyTransfer.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h> 


/* Arguments sizes and Timeout constants */
#define AutoReset_Timeout    500        // If no device connects for this milliseconds, ESP will reset 'Arguments'
#define Argument_Size        6          // Number of arguments to be fetch and store in global 'Arguments'
#define SensorBuffer_Size    100        // Max number of characters to be sent back to remote device

/* Create MyServer object that listens on port number 80 (which is default http port) */
ESP8266WebServer MyServer(80);

/* Access Point's SSID and Password */
const char *SsID = "WIoT - Hydroflyer";    // SsID should not be more than 15 chars
const char *Password = "12345678";

/*
EasyTransfer library makes it much easy to send and receive composite data over Serial.
Create separate object for sending and receiving.
*/
EasyTransfer ETin, ETout;

/* 'SEND_DATA_STRUCTURE' MUST BE IDENTICAL ON GATEWAY SIDE (WITH NAME OF 'RECEIVE_DATA_STRUCTURE') */
struct SEND_DATA_STRUCTURE
{
	byte Arguments[Argument_Size];
};

/* 'RECEIVE_DATA_STRUCTURE' MUST BE IDENTICAL ON GATEWAY SIDE (WITH NAME OF 'SEND_DATA_STRUCTURE') */
struct RECEIVE_DATA_STRUCTURE
{
	char ReplyBuffer_100[SensorBuffer_Size];
};

SEND_DATA_STRUCTURE OutgoingData;
RECEIVE_DATA_STRUCTURE IncomingData;


/* Global Counters */
uint8_t C1;
unsigned long LastAccessTime;  // To reset 'Arguments' if no connection was made in last AutoReset_Timeout milliseconds.



/* Handles index or root requests */
void HandleRoot() {
	MyServer.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate", false);
	MyServer.sendHeader("Pragma", "no-cache", false);
	MyServer.sendHeader("Expires", "1000", false);
	MyServer.send(200, "text/html", "<html><head><title>Windows IoT - Hydroflyer</title></head><body>Hydrofler is online.<br/>Windows IoT is the heart of the boat.<br/>To maneuver boat, please refer: www.hackster.io/AnuragVasanwala/windows-10-iot-core-hydroflyer");
}

/* Handles maneuver requests */
void HandleManeuver() {
	/* Parse arguments and store it to Arguments byte array */
	for (C1 = 0; (C1 < Argument_Size) && (C1 < MyServer.args()); C1++)
	{
		/* Convert string argument value to equivalent byte */
		OutgoingData.Arguments[C1] = (byte)(MyServer.arg(C1).toInt());
	}

	/* Prepare html headers to instruct remote device to not to cache page */
	MyServer.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate", false);
	MyServer.sendHeader("Pragma", "no-cache", false);
	MyServer.sendHeader("Expires", "0", false);

	/* Send data to remote device */
	MyServer.send(200, "text/plain", IncomingData.ReplyBuffer_100);

	LastAccessTime = millis();
}

void setup()
{
	/* Wait for a one and half second to make ESP stable */
	delay(1500);

	/*
		Configure and start Serial Communication with gateway.
		SERIAL BAUD RATE MUST BE IDENTICAL GATEWAY, TOO.
	*/
	Serial.begin(115200);

	/*
		Setup ESP as AP with 'SsID' and 'Password'.
		Please make sure to do not give SSID more than 15
		and password length must also be less than 10 char
		in order to achieve quick response from ESP.
	*/
	WiFi.mode(WIFI_AP);
	WiFi.softAP(SsID, Password);

	/* Handle index or root GET request on function HandleRoot */
	MyServer.on("/", HandleRoot);

	/* Handle Maneuver GET request on function HandleManeuver */
	MyServer.on("/Maneuver", HandleManeuver);

	/* Start MyServer */
	MyServer.begin();

	/* Initialize ReplyBuffer to show initial message */
	IncomingData.ReplyBuffer_100[0] = 'B';
	IncomingData.ReplyBuffer_100[1] = 'O';
	IncomingData.ReplyBuffer_100[2] = 'O';
	IncomingData.ReplyBuffer_100[3] = 'T';
	IncomingData.ReplyBuffer_100[4] = 'I';
	IncomingData.ReplyBuffer_100[5] = 'N';
	IncomingData.ReplyBuffer_100[6] = 'G';
	IncomingData.ReplyBuffer_100[7] = '\0';

	/*
		Initialize ETin for incoming data while ETout for outgoing data
			+ Received data from gateway will be stored in 'IncomingData'
			+ 'OutgoingData' will holds data to be send to gateway on request
	*/
	ETin.begin(details(IncomingData), &Serial);
	ETout.begin(details(OutgoingData), &Serial);
}

void loop()
{
	/* Periodically check for request on Web Server */
	MyServer.handleClient();

	/* If gateway sends data to ESP, receive it and send back 'Arguments' */
	if (ETin.receiveData())
	{
		/* If no device has been connected for last 'AutoReset_Timeout' time, reset Arguments */
		if (millis() - LastAccessTime > AutoReset_Timeout)
		{
			for (C1 = 0; C1 < Argument_Size; C1++)
			{
				OutgoingData.Arguments[C1] = 0;
			}
		}

		/* Send back 'Arguments' to Gateway */
		ETout.sendData();
	}
}
Gateway Sketch (Arduino Sketch)C/C++
/*
	Gateway sketch for Hydroflyer (Boat) (RPi2 + WinIoT)
	https://www.hackster.io/AnuragVasanwala/windows-10-iot-core-hydroflyer-f83190

	NOTE: This sketch is tested and meant for Arduino Nano.

	Gateway sketch for Arduino is still in early development. Contribution is most welcomed.

	Objectives:
		+ Provide support for ADC, PWM, Serial to I2C Master on request
		+ Periodically send ESP8266-01 'ReplyBuffer_100' received from I2C Master
		+ Once 'ReplyBuffer_100' is sent to ESP, ESP will send back 'Arguments' parsed from 'Maneuver' GET request so read them.
		+ Provide support for GPS (Device: uBlox New6mV2 with 9600 baud) to I2C Master on demand

	: WARNING :
		+ 'Argument_Size' AND 'SensorBuffer_Size' MUST BE IDENTICAL ON ESP8266-01 SKETCH.
		+ SERIAL BAUD RATE MUST BE SAME ON BOTH SIDE (GATEWAY & ESP).
		+ 'SEND_DATA_STRUCTURE' MUST BE IDENTICAL ON ESP8266 SIDE (WITH NAME OF 'RECEIVE_DATA_STRUCTURE').
		+ 'RECEIVE_DATA_STRUCTURE' MUST BE IDENTICAL ON ESP8266 SIDE (WITH NAME OF 'SEND_DATA_STRUCTURE').
		+ YOU MUST HAVE 'EasyTransfer' LIBRARY IN YOUR ARDUINO FOLDER.
		  TO INSTALL 'EasyTransfer', REFER: https://github.com/madsci1016/Arduino-EasyTransfer
		  THIS REPOSITORY CONTAINS:
			+ EasyTransfer
			+ EasyTransferI2C
			+ EasyTransferVirtualWire
			+ SoftEasyTransfer

			BUT YOU ONLY HAVE TO COPY FIRST FOLDER 'EasyTransfer' TO YOUR ARDUINO's LIBRARY FOLDER
*/

/* Global Include */
#include <Wire.h>
#include <TinyGPS++.h>
#include <EasyTransfer.h>
#include <SoftwareSerial.h>

/* Our pretty Gateway's name or let's say address */
#define MyGateway1 0x40

/* Arguments sizes and Timeout constants */
#define Argument_Size		6          // Number of arguments to be fetch and store in global 'Arguments'
#define SensorBuffer_Size   100        // Max number of characters to be sent back to remote device

/* GPS Pin defination & Baud Rate*/
#define GPS_RX_PIN			8
#define GPS_TX_PIN			9
#define GPS_BAUD			9600       // Please confirm your GPS's baud. If it is 115200, them use AltSoftSerial instead of SoftwareSerial

/*
	[ DO NOT MODIFY ]
	Following are the list of Gateway Protocol Mode
	They must be identical on both side (Windows IoT Sketch and Arduino Sketch)
	Please refer Windows IoT Hydroflyser's Header File: Library\Gateway (I2C)\Gateway.h
*/
#define GATEWAY_CTRL_pinMode								10
#define GATEWAY_CTRL_digitalWrite							11
#define GATEWAY_CTRL_digitalRead							12
#define GATEWAY_CTRL_analogWrite							13
#define GATEWAY_CTRL_analogRead								14
#define GATEWAY_CTRL_getManeuverBytes						15
#define GATEWAY_CTRL_getRequestedURL						16
#define GATEWAY_CTRL_getGPS									17
#define GATEWAY_CTRL_sendSensorData_ToRemoteDevice			18
#define GATEWAY_CTRL_sendString_ToRemoteDevice				19
#define GATEWAY_CTRL_sendString_ToRemoteDevice_Continued	20

/* Byte manipulation macro */
#define DoubleToByte(buf,doubleData) \
  *((double *)buf) = doubleData;

#define IntegerToByte(buf,intData) \
  *((int *)buf) = intData;

/* Global Variables */
byte CTRL, Pin, BoolValue, Temp_X[SensorBuffer_Size], Value;
uint16_t Index;
int IntValue;

/* Global Counters */
byte C1 = 0;

/* GPS Device object & Variable */
TinyGPSPlus GPD_Device;
byte GPS_SendBuffer[16], Buffer_4[4], Buffer_2[2];

/*
	GPS Device UART Link

	: WARNING :
		IF YOUR GPS DEVICE SUPPORTS 115200 BAUD, PLEASE USE 'AltSoftSerial' LIBRARY INSTEAD OF 'SoftwareSerial'
*/
SoftwareSerial GPS_UART(GPS_RX_PIN, GPS_TX_PIN);

/*
	EasyTransfer library makes it much easy to send and receive composite data over Serial.
	Create separate object for sending and receiving.
*/
EasyTransfer ETin, ETout;

/* 'RECEIVE_DATA_STRUCTURE' MUST BE IDENTICAL ON GATEWAY SIDE (WITH NAME OF 'SEND_DATA_STRUCTURE') */
struct RECEIVE_DATA_STRUCTURE
{
	byte Arguments[Argument_Size];
};

/* 'SEND_DATA_STRUCTURE' MUST BE IDENTICAL ON GATEWAY SIDE (WITH NAME OF 'RECEIVE_DATA_STRUCTURE') */
struct SEND_DATA_STRUCTURE
{
	char ReplyBuffer_100[SensorBuffer_Size];
};

SEND_DATA_STRUCTURE mydata_out;
RECEIVE_DATA_STRUCTURE mydata_in;

void setup()
{
	/* Initialize Gateway as I2C slave and register Request and Response handler */
	Wire.begin(MyGateway1);
	Wire.onRequest(onRequest);
	Wire.onReceive(onReceive);

	/* Initialize Hardware Serial to communicate with ESP8266-01 with 115200 baud. */
	Serial.begin(115200);

	/* Initialize Software Serial to communicate with GPS (uBlox Neo6mV2) with GPS_BAUD baud. */
	GPS_UART.begin(GPS_BAUD);

	/*
		Initialize ETin for incoming data while ETout for outgoing data
			+ 'OutgoingData' will holds data to be send to ESP on request
			+ Received data from ESP will be stored in 'IncomingData'
			
	*/
	ETin.begin(details(mydata_in), &Serial);
	ETout.begin(details(mydata_out), &Serial);
	
	/* Initial response to Remote Device (WP8.1/10) */
	mydata_out.ReplyBuffer_100[0] = 'B';
	mydata_out.ReplyBuffer_100[1] = 'O';
	mydata_out.ReplyBuffer_100[2] = 'O';
	mydata_out.ReplyBuffer_100[3] = 'T';
	mydata_out.ReplyBuffer_100[4] = 'I';
	mydata_out.ReplyBuffer_100[5] = 'N';
	mydata_out.ReplyBuffer_100[6] = 'G';
	mydata_out.ReplyBuffer_100[7] = ':';
	mydata_out.ReplyBuffer_100[8] = 'G';
	mydata_out.ReplyBuffer_100[9] = 'A';
	mydata_out.ReplyBuffer_100[10] = 'T';
	mydata_out.ReplyBuffer_100[11] = 'E';
	mydata_out.ReplyBuffer_100[12] = 'W';
	mydata_out.ReplyBuffer_100[13] = 'A';
	mydata_out.ReplyBuffer_100[14] = 'Y';
	mydata_out.ReplyBuffer_100[15] = '\0';

}
unsigned long LastUpdateTime;

void loop() {
	/* Periodically send response string to ESP (received from RPi2) and take back 'Arguments' from ESP */
	if (millis() - LastUpdateTime > 30)
	{
		/* Send string received from RPi2 */
		ETout.sendData();
		
		/* Wait for a while before receiving 'Arguments' from ESP */
		delay(30);

		/* Receive 'Arguments' from ESP */
		if (ETin.receiveData()){}

		/* Update time to avoid frequent calls */
		LastUpdateTime = millis();
	}

	/* Read and parse GPS Data if ready */
	while (GPS_UART.available() > 0)
		if (GPD_Device.encode(GPS_UART.read()))
			FetchGPSData();
}

/* Executes when RPi2 requests number of bytes */
void onRequest()
{
	/* CTRL will be set by onReceived */
	switch (CTRL)
	{
	case GATEWAY_CTRL_digitalRead:
		Wire.write(BoolValue);
		break;
	case GATEWAY_CTRL_analogRead:
		IntegerToByte(Buffer_2, IntValue);
		Wire.write(Buffer_2, 2);
		break;
	case GATEWAY_CTRL_getManeuverBytes:
		Wire.write(mydata_in.Arguments, Argument_Size);
		break;
	case GATEWAY_CTRL_getRequestedURL:
		/* NOT IMPLEMENTED YET; CONTRIBUTION IS MOST WELCOMED */
		break;
	case GATEWAY_CTRL_getGPS:
		Wire.write(GPS_SendBuffer, 16);
		break;
	case GATEWAY_CTRL_sendSensorData_ToRemoteDevice:
	case GATEWAY_CTRL_sendString_ToRemoteDevice:
	case GATEWAY_CTRL_sendString_ToRemoteDevice_Continued:
		break;
	default:
		break;
	}
}

void onReceive(int NOB)
{
	CTRL = Wire.read();

	switch (CTRL)
	{
	case GATEWAY_CTRL_pinMode:
		Pin = Wire.read();
		Value = Wire.read();
		pinMode(Pin, Value);
		break;
	case GATEWAY_CTRL_digitalWrite:
		Pin = Wire.read();
		Value = Wire.read();
		digitalWrite(Pin, Value);
		break;
	case GATEWAY_CTRL_digitalRead:
		Pin = Wire.read();
		BoolValue = digitalRead(Pin);
		break;
	case GATEWAY_CTRL_analogWrite:
		analogWrite(Wire.read(), Wire.read());
		break;
	case GATEWAY_CTRL_analogRead:
		IntValue = analogRead(Wire.read());
		break;
	case GATEWAY_CTRL_getManeuverBytes:
	case GATEWAY_CTRL_getRequestedURL:
	case GATEWAY_CTRL_getGPS:
		break;
	case GATEWAY_CTRL_sendSensorData_ToRemoteDevice:
	case GATEWAY_CTRL_sendString_ToRemoteDevice:
		Index = 0;
		for (C1 = 0; C1 < 31; C1++)
		{
			mydata_out.ReplyBuffer_100[Index++] = Wire.read();
		}
		mydata_out.ReplyBuffer_100[Index] = '\0';
		break;
	case GATEWAY_CTRL_sendString_ToRemoteDevice_Continued:
		for (C1 = 0; C1 < 31; C1++)
		{
			mydata_out.ReplyBuffer_100[Index++] = Wire.read();
		}
		if (Index < 99)
		{
			mydata_out.ReplyBuffer_100[Index] = '\0';
		}
		break;
	default:
		break;
	}
	while (Wire.available())
	{
		Wire.read();
	}
}

void FetchGPSData()
{
	//Validation Byte
	bitWrite(GPS_SendBuffer[0], 0, GPD_Device.location.isValid());
	bitWrite(GPS_SendBuffer[0], 1, GPD_Device.altitude.isValid());
	bitWrite(GPS_SendBuffer[0], 2, GPD_Device.date.isValid());
	bitWrite(GPS_SendBuffer[0], 3, GPD_Device.time.isValid());
	bitWrite(GPS_SendBuffer[0], 4, GPD_Device.speed.isValid());
	//Future Use
	bitClear(GPS_SendBuffer[0], 5);
	bitClear(GPS_SendBuffer[0], 6);
	bitClear(GPS_SendBuffer[0], 7);

	//Location : Latitude
	DoubleToByte(Buffer_4, GPD_Device.location.lat());
	GPS_SendBuffer[1] = Buffer_4[0];
	GPS_SendBuffer[2] = Buffer_4[1];
	GPS_SendBuffer[3] = Buffer_4[2];
	GPS_SendBuffer[4] = Buffer_4[3];

	//Location : Longitude
	DoubleToByte(Buffer_4, GPD_Device.location.lng());
	GPS_SendBuffer[5] = Buffer_4[0];
	GPS_SendBuffer[6] = Buffer_4[1];
	GPS_SendBuffer[7] = Buffer_4[2];
	GPS_SendBuffer[8] = Buffer_4[3];

	//Date : Day
	GPS_SendBuffer[9] = (byte)GPD_Device.date.day();
	//Date : Month
	GPS_SendBuffer[10] = (byte)GPD_Device.date.month();
	//Date : Year
	IntegerToByte(Buffer_2, GPD_Device.date.year());
	GPS_SendBuffer[11] = Buffer_2[0];
	GPS_SendBuffer[12] = Buffer_2[1];

	//Time : Hour
	GPS_SendBuffer[13] = (byte)GPD_Device.time.hour();
	//Time : Minute
	GPS_SendBuffer[14] = (byte)GPD_Device.time.minute();
	//Time : Second
	GPS_SendBuffer[15] = (byte)GPD_Device.time.second();
}

Schematics

Flashing/Programming ESP8266-01
ESP8266-01%20-%20Flash-Programming%20Mode.fzz
Hydroflyer - Circuit Reference
Circuit%20reference
Hydroflyer - Circuit Reference (Fritzing)
Hydroflyer%20Circuit%20Reference.fzz
Hydroflyer - Circuit Reference
Circuit%20reference
Hydroflyer - Circuit Reference (Fritzing)
Hydroflyer%20Circuit%20Reference.fzz

Comments

Author

Asv2
Anurag S. Vasanwala
  • 4 projects
  • 416 followers

Additional contributors

Published on

November 3, 2015

Members who respect this project

DefaultAdambenzPorrey0c48a85Default10405525 10152894196026419 3492377483201455797 nDefaultDefault

and 49 others

See similar projects
you might like

Similar projects you might like

OH HAI! on Windows 10 IoT Core

Project in progress by BuddyC

  • 12,530 views
  • 3 comments
  • 48 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 297,272 views
  • 98 comments
  • 706 respects

Windows 10 IoT Core: UltraSonic Distance Mapper

Project showcase by Anurag S. Vasanwala

  • 51,776 views
  • 23 comments
  • 138 respects

Solar Tracker with Live Data Feed - Windows IoT

Project tutorial by Jed Hodson

  • 10,088 views
  • 1 comment
  • 18 respects

Windows 10 IoT Plant Monitoring System

Project tutorial by Team BME-AUT

  • 11,650 views
  • 4 comments
  • 55 respects

A PM2.5 and PM 10 Detector design for Windows 10 UWP App

Project tutorial by Jiong Shi

  • 8,175 views
  • 5 comments
  • 24 respects
Add projectSign up / Login