Georgi Angelov
Published © MIT

Azure Sphere - PlatformIO - Arduino & Linux

Azure Sphere for PlatformIO - Arduino and Linux applications

BeginnerFull instructions provided1 hour2,024
Azure Sphere - PlatformIO - Arduino & Linux

Things used in this project

Story

Read more

Schematics

Azure

ARDUINO

in progress

Code

Template

C/C++
/*  Copyright (c) Microsoft Corporation. All rights reserved.
        Licensed under the MIT License. 
    PlatformIO 2019 Georgi Angelov
    https://github.com/Wiz-IO
    http://www.wizio.eu/
    OPEN: 'platformio.ini' and edit your settings
    OPEN: 'src/app_manifest.json' and enter your 'Capabilities'
 */

#include <errno.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#include "applibs_versions.h"
#include <applibs/gpio.h>
#include <applibs/log.h>
#include "epoll_timerfd_utilities.h"

static volatile sig_atomic_t terminationRequired = false;
static int epollFd = -1;

int main(int argc, char *argv[])
{
    Log_Debug("Azure Sphere PlatformIO 2019 WizIO\n");
    while (!terminationRequired) {
        if (WaitForEventAndCallHandler(epollFd) != 0) {
            terminationRequired = true;
        }
    }
    Log_Debug("End\n");
    return 0;
}

Arduino PubSub Client

Arduino
Simple MQTT to Eclipse
#include <Arduino.h>
#include <applibs/networking.h>
#include <wifiClient.h>
wifiClient cc;

/* 
Chrome - MQTTLens
    https://chrome.google.com/webstore/detail/mqttlens/hemojaaeigabkbcookmlgmdigohjobjm?hl=en

Nick O'Leary Library http://knolleary.net    
*/

#include <PubSubClient.h>
PubSubClient mqtt("iot.eclipse.org", 1883, cc); // https://iot.eclipse.org/getting-started/

int led_state = 0;

void callback(char *topic, byte *payload, unsigned int length)
{
  Serial.printf("[MSG] <%s> %.*s\n", topic, length, payload);
}

void reconnect()
{
  while (!mqtt.connected())
  {
    Serial.println("[MQTT] Connecting to Eclipse...");
    char client_id[64];
    snprintf(client_id, 64, "WIZIO_%d", millis()); // create unique id
    Serial.printf("[MQTT] ClientID: %s\n", client_id);
    if (mqtt.connect(client_id))
    {
      Serial.println("[MQTT] Connected");
      mqtt.publish("wizio/output", "Hello world");
      mqtt.subscribe("wizio/input");
    }
    else
    {
      Serial.printf("[ERROR] MQTT Connect: %d", (int)mqtt.state());
      delay(10000); // Wait reconnect
      Serial.println("[MQTT] Reconnecting");
    }
  }
}

void setup()
{
  Serial.begin(115200);
  pinMode(LED_GREEN, OUTPUT);
  Serial.println("\nAzure Sphere 2019 Georgi Angelov");
  Serial.println("Arduino - PubSub - PlatformIO");
  Serial.println("Azure Sphere MT3620 Starter AES-MS-MT3620-SK-G by Avnet");
  Serial.println("Waithing WIFI");
  bool outIsNetworkingReady = 0;
  if (Networking_IsNetworkingReady(&outIsNetworkingReady) < 0 && 0 == outIsNetworkingReady)
  {
    Serial.print(".");
    digitalWrite(LED_GREEN, led_state);
    led_state ^= 1;
    delay(100);
  }
  mqtt.setCallback(callback);
}

void loop()
{
  static int t = 0;
  if (!mqtt.connected())
    reconnect();
  mqtt.loop();
  if (0 == t % 100)
  {
    digitalWrite(LED_GREEN, led_state); // blink toggle
    led_state ^= 1;
  }
}

OLED

C/C++
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display;

void TEST_OLED()
{
  Serial.println("[APP] OLED TEST");
  display.begin(SSD1306_SWITCHCAPVCC, 0x78 >> 1); // 7-bits
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("  Arduino");
  display.setTextColor(BLACK, WHITE);
  display.println(" Azure    ");
  display.println("   Sphere ");
  display.setTextSize(1);
  display.setTextColor(WHITE, BLACK);
  display.println();
  display.println("      WizIO 2019");
  display.display();
}

void setup()
{
  Serial.begin(115200);
  Serial.println("\nArduino Azure Sphere 2019 Georgi Angelov");
  TEST_OLED();
}

void loop()
{
  Serial.println("[APP] LOOP");
  delay(10000);
}

Project link

Credits

Georgi Angelov

Georgi Angelov

9 projects • 15 followers

Comments