postman-code-generators icon indicating copy to clipboard operation
postman-code-generators copied to clipboard

[WIP] Arduino code generator

Open tirtawr opened this issue 4 years ago • 0 comments

Issue https://github.com/postmanlabs/postman-code-generators/issues/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

tirtawr avatar Mar 27 '20 01:03 tirtawr