Giter Club home page Giter Club logo

ardfstcplibrary's Introduction

ArdFSTCPLibrary

Arduino Flight Simulator TCP Library.

Purpose

This library provides routines to enable a WiFi enables Arduino Uno to connect to the Flight Simulator Listener.

Required Libraries

Functions

Constructor

FlightSimulator(Client , ServerName, ServerPort , BoardName )

  • Wifi Client. I have not tested this with anyother network clients yet.
  • ServerName. IP address or Name of the Sim Listener Server
  • ServerPort. Port that the Sim listener REST API is listening on
  • BoardName. A unique name for this board.

Methods

int Register( outputs[] )

  • Returns the port that will provide the data
  • Outputs. A String array containing a list of SIMVARS i.e {"PLANE ALTITUDE" , "PLANE LATITUDE" }

void Read( *SimulatorData )

  • SimulatorData is a pointer to a DynamicJsonDocument object. This will contain the data read from the Flight Simulator, and can be accessed using SimulatorData["PLANE ALTITUDE"]

void Write( *SimulatorData )

  • SimulatorData is a pointer to a DynamicJsonDocument object. This will contain the data read from the Flight Simulator, and can be accessed using SimulatorData["PLANE ALTITUDE"]

Simple Example

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

#include "<LOCATION OF YOUR SECRETS>\secrets.h"

int status = WL_IDLE_STATUS;
int ListenPort = 0;

String RequiredOutputs[1] = {"PLANE ALTITUDE"};
DynamicJsonDocument SimulatorData(100) ;

WiFiClient wifi;
// HOST_NAME is the name of the SimListener Server
// PORT is the REST API interface port 
FlightSimulator fsclient = FlightSimulator( wifi , HOST_NAME , HOST_PORT );

void setup() {
   Serial.begin(9600); // Start Serial Interface
}

void loop() {

  if( status == WL_CONNECTED )
  {   
    if( !fsclient.connected())
    {
      Serial.println( "Registering");
      ListenPort = fsclient.Register( RequiredOutputs ); // Register your board and get a PORT back
      if( ListenPort > 0 )
      {
        wifi.connect(  HOST_NAME , ListenPort ); // Connect to that PORT so you can send and recieve data
        Serial.println( "Connected to host");
      }
    }

    if( fsclient.connected())
    {
      fsclient.Read(&SimulatorData) ;   // Read data
      fsclient.Write(&SimulatorData) ;  // Write it back as an example
    }

    String Altitude = SimulatorData["PLANE ALTITUDE"];
    Serial.println( Altitude );
  }
  else
  {
    delay(5000);
    status = WiFi.begin(ssid, pass); // Connect to WiFi 
  } 
  delay(1000);
}

ardfstcplibrary's People

Contributors

sfawcett123 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.