Advertisement
Guest User

wolfSSL

a guest
Jun 28th, 2017
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "application.h"
  2. #include "wolfssl/ssl.h"
  3. #include "spark_wiring_tcpclient.h"
  4.  
  5. //EthernetClient client;
  6. TCPClient client;
  7.  
  8. WOLFSSL_CTX* ctx = 0;
  9. WOLFSSL* ssl = 0;
  10. WOLFSSL_METHOD* method = 0;
  11.  
  12. int EthernetSend(WOLFSSL* ssl, char* msg, int sz, void* ctx) {
  13.   int sent = 0;
  14.   sent = client.write((byte*)msg, sz);
  15.   return sent;
  16. }
  17.  
  18. int EthernetReceive(WOLFSSL* ssl, char* reply, int sz, void* ctx) {
  19.   int ret = 0;
  20.   while (client.available() > 0 && ret < sz) {
  21.     reply[ret++] = client.read();
  22.   }
  23.   return ret;
  24. }
  25.  
  26. void setup() {
  27.   RGB.control(true);
  28.  
  29.   ctx = wolfSSL_CTX_new(method);
  30.   if (ctx == NULL) {
  31.     Serial.println("unable to get ctx");
  32.     return;
  33.   }
  34.   // initialize wolfSSL using callback functions
  35.   wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
  36.   wolfSSL_SetIOSend(ctx, EthernetSend);
  37.   wolfSSL_SetIORecv(ctx, EthernetReceive);
  38. }
  39.  
  40. void loop() {
  41.   RGB.color( 128,128,0);
  42.   delay(500);
  43.   RGB.color( 255,0,0);
  44.   delay(500);
  45. }
Advertisement
RAW Paste Data Copied
Advertisement