Skip to content

Conversation

tirtawr
Copy link

@tirtawr tirtawr commented Mar 27, 2020

Issue #228 adding support for Arduino Code Generation

Below is a sample of the generated code:

#include <SPI.h>
#include <WiFiNINA.h>

char ssid[] = "myNetwork";    //  your network SSID (name)
char pass[] = "myPassword";   // your network password

int status = WL_IDLE_STATUS;
char server[] = "echo.getpostman.com";

WiFiClient client;

void setup() {
  Serial.begin(9600);
  Serial.println("Attempting to connect to WPA network...");
  Serial.print("SSID: ");
  Serial.println(ssid);

  status = WiFi.begin(ssid, pass);
  if ( status != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    while(true);
  }
  else {
    Serial.println("Connected to wifi");
    Serial.println("
Starting connection...");
    if (client.connect(server, 443)) {
      Serial.println("connected");
      client.println("POST /post HTTP/1.1");
      client.println("Host: echo.getpostman.com");
      client.println("Content-Type: application/json");
      client.println("");
      client.println("my-body-variable=Something Awesome!");
    }
  }
}

void loop() {
  printResponse();
}

void printResponse() {
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }
}

Some notes:

  • Newman tests would not be possible because the code is meant to be run on a microcontroller

Still TODO:

  • Utilize the provided fixtures for test
  • Do some sort of Blackbox test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant