(10 intermediate revisions by the same user not shown)
Line 3: Line 3:
  
 
=Hornbill IO operation=
 
=Hornbill IO operation=
In this tutorial we will see how to control the ESP32 pins using the AWS IOT. For this we will be using the Hornbill_IO library. Hornbill_IO currently supports the below four operation which will be extended in the near future.
+
In this tutorial we will see how to control the ESP32 pins using the AWS IOT. For this we will be using the Hornbill_IO library. Hornbill_IO library currently supports the below four operation which will be extended in the near future.
 
#digitalRead
 
#digitalRead
 
#digitalWrite
 
#digitalWrite
Line 11: Line 11:
 
=Hornbill IO JSON Format=
 
=Hornbill IO JSON Format=
 
We have a specific protocol/json format defined for the IO operation.
 
We have a specific protocol/json format defined for the IO operation.
Below is the Json format for sending the data from Control Unit to ESP32  
+
Below is the Json format for sending the data from Control Unit to ESP32 for '''writing''' a '''logic 1''' to '''pin 13'''.
 
<html>
 
<html>
 
<script src="https://gist.github.com/SaheblalBagwan/586e9192b6401fc7b2aec1a7a8968fc5.js"></script>
 
<script src="https://gist.github.com/SaheblalBagwan/586e9192b6401fc7b2aec1a7a8968fc5.js"></script>
 
</html>
 
</html>
By the above format Control Unit wants to '''write''' a '''logic 1''' to '''pin 13'''.
 
  
  
Below is the Json format for reporting the data from ESP32 to Server.  
+
 
 +
Below is the Json format for reporting the data from ESP32 to Server. The device is reporting the '''analog''' value('''1023''') of '''pin 36''' to the server.
 
<html>
 
<html>
 
<script src="https://gist.github.com/SaheblalBagwan/f0207bf8280ff75994f2744ef1b6af94.js"></script>
 
<script src="https://gist.github.com/SaheblalBagwan/f0207bf8280ff75994f2744ef1b6af94.js"></script>
 
</html>
 
</html>
Here the device is reporting the '''analog''' value('''1023''') of '''pin 36''' .
+
.
  
 
=Hornbill IO Structure=
 
=Hornbill IO Structure=
Line 29: Line 29:
 
<script src="https://gist.github.com/SaheblalBagwan/39f374e6513292f9158b6d00b727e2a2.js"></script>
 
<script src="https://gist.github.com/SaheblalBagwan/39f374e6513292f9158b6d00b727e2a2.js"></script>
 
</html>
 
</html>
 +
<br><br>
 +
 +
=Hornbill IO Functions=
 +
{| class="table table-striped table-hover table-condensed table-bordered"
 +
|-class="info"
 +
!Function || int parseRequest(char *json_string, hornbill_IO_type_t *ioReq);
 +
|-
 +
|description || This function parses the input string and extract the requested '''operation''', '''pinNum''' , '''value''' and copies them to I/p structure pointer.
 +
|-
 +
|Arguments ||
 +
*char *json_string--> Received json string
 +
*hornbill_IO_type_t *ioReq--> Parsed '''operation''', '''pinNum''' and '''value''' is copied to this structure
 +
|-
 +
|returns ||
 +
*HORNBILL_IO_REQUEST_VALID = 0,
 +
*HORNBILL_IO_REQUEST_JSON_INVALID = 1,
 +
*HORNBILL_IO_REQUEST_NOACTION = 2
 +
|}
 +
 +
 +
{| class="table table-striped table-hover table-condensed table-bordered"
 +
|-class="info"
 +
!Function || int processRequest(hornbill_IO_type_t *ioReq)
 +
|-
 +
|description || This function handles the requested IO operation. In case of read it reads the pin and stores its value which can be reported back.
 +
|-
 +
|Arguments || hornbill_IO_type_t *ioReq--> Structure pointer containing the requested operation , pinNum and its value
 +
|-
 +
|returns||
 +
TDB
 +
|}
 +
 +
 +
{| class="table table-striped table-hover table-condensed table-bordered"
 +
|-class="info"
 +
!Function || void createPayload(char *payload_ptr, hornbill_IO_type_t *ioReq)
 +
|-
 +
|description || This function is used to create a reporting payload by using the information passed in the structure(operation, pinNum and value)
 +
|-
 +
|Arguments || hornbill_IO_type_t *ioReq--> Structure pointer containing the reporting information (operation , pinNum and its value)
 +
|-
 +
|returns||
 +
void
 +
|}
  
 
=Code=
 
=Code=
Line 37: Line 81:
 
=Testing=
 
=Testing=
  
====digitalRead====
+
==digitalRead==
 +
[[File:DigitalReadTest.jpg]]
  
====digitalWrite====
+
==digitalWrite==
  
====analogRead====
+
==analogRead==
  
====analogWrite====
+
==analogWrite==

Latest revision as of 19:39, 13 April 2017

In the last tutorial we saw how to use the Arduino ESP32 AWS IOT library to configure an AWS client to subscribe/publish to a topic/thing. At the end of the tutorial we logged the temperature and humidity using DTH11 sensor.

Hornbill IO operation

In this tutorial we will see how to control the ESP32 pins using the AWS IOT. For this we will be using the Hornbill_IO library. Hornbill_IO library currently supports the below four operation which will be extended in the near future.

  1. digitalRead
  2. digitalWrite
  3. analogRead
  4. analogWrite

Hornbill IO JSON Format

We have a specific protocol/json format defined for the IO operation. Below is the Json format for sending the data from Control Unit to ESP32 for writing a logic 1 to pin 13.


Below is the Json format for reporting the data from ESP32 to Server. The device is reporting the analog value(1023) of pin 36 to the server. .

Hornbill IO Structure

The above Json format is mapped to internal Hornbill IO control structure as below. This may change in the future as we add more functionality to Hornbill IO library.

Hornbill IO Functions

Function int parseRequest(char *json_string, hornbill_IO_type_t *ioReq);
description This function parses the input string and extract the requested operation, pinNum , value and copies them to I/p structure pointer.
Arguments
  • char *json_string--> Received json string
  • hornbill_IO_type_t *ioReq--> Parsed operation, pinNum and value is copied to this structure
returns
  • HORNBILL_IO_REQUEST_VALID = 0,
  • HORNBILL_IO_REQUEST_JSON_INVALID = 1,
  • HORNBILL_IO_REQUEST_NOACTION = 2


Function int processRequest(hornbill_IO_type_t *ioReq)
description This function handles the requested IO operation. In case of read it reads the pin and stores its value which can be reported back.
Arguments hornbill_IO_type_t *ioReq--> Structure pointer containing the requested operation , pinNum and its value
returns

TDB


Function void createPayload(char *payload_ptr, hornbill_IO_type_t *ioReq)
description This function is used to create a reporting payload by using the information passed in the structure(operation, pinNum and value)
Arguments hornbill_IO_type_t *ioReq--> Structure pointer containing the reporting information (operation , pinNum and its value)
returns

void

Code

Testing

digitalRead

DigitalReadTest.jpg

digitalWrite

analogRead

analogWrite