Gideon Hooberman
Published © GPL3+

WISDome - Weapon Identification System Dome

A new way to save lives by neutralizing the attacker before he can act.

BeginnerWork in progress3,716
WISDome - Weapon Identification System Dome

Things used in this project

Story

Read more

Schematics

Arduino MKR1000

Code

Arduino Code

C/C++
Connects to a wifi and send a message to the cloud
#include <SPI.h>
#include <WiFi101.h>

char hex[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

//device id
char id[] = "MKR1000";

// wifi configuration
char ssid[] = "hershkofuks 2.4"; //  your network SSID (name)
char pass[] = "0523967311";    // your network password (use for WPA, or use as key for WEP)

//azure iot hub configuration
char hostname[] = "WISDome.azure-devices.net";    // host name address for your Azure IoT Hub
char authSAS[] = "SharedAccessSignature sr=WISDome.azure-devices.net%2fdevices%2fMKR1000&sig=TFrT2ErDuCY3LlDBnP3IX3MftrzgfrmACjyNdUHnMvE%3d&se=1488976355";

//message send URI
String azureSend = "/devices/MKR1000/messages/events?api-version=2016-02-03";

//time configuration
unsigned long lastConnectionTime = 0;            
const unsigned long pollingInterval = 1000*60; // 1 min 

int status = WL_IDLE_STATUS;
WiFiSSLClient client;

void setup() {
  Serial.begin(9600);
  //check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    status = WiFi.begin(ssid, pass);
    Serial.print("attempting to connect to: ");
    Serial.print(ssid);
    Serial.print(" with password: ");
    Serial.println(pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.print("connected to: ");
  Serial.println(ssid);
}

void loop() 
{
  String response = "";
  char c;
  //read response if the client is availabe
  while (client.available()) {
    c = client.read();
    response.concat(c);
  }
  //print the response
  Serial.print(response);
  
  // polling..if pollingInterval has passed
  if (millis() - lastConnectionTime > pollingInterval) {
    //get router's mac address
    byte mac_bytes[6];
    WiFi.BSSID(mac_bytes);

    //convert it to a string
    String mac = "";
    for(int i = 0 ; i < 6 ; i++){
      mac.concat(hex[mac_bytes[i]/16]);
      mac.concat(hex[mac_bytes[i]%16]);
      if(i!=5 )mac.concat(":");
    }

    //send it along with the device id
    SendMessage(id,mac);
    
    //note the time that the connection was made:
    lastConnectionTime = millis();
  }
}

void SendMessage(String id, String mac)
{
    //set content to [{"id":"actual id","mac":"router mac adress"}]
    String content = "";
    content.concat("[{\"id\":\"");
    content.concat(id);
    content.concat("\",\"mac\":\"");
    content.concat(mac);
    content.concat("\"}]");
    
    // close any connection before send a new request.
    client.stop();
  
    // if the connection was successful:
    if (client.connect(hostname, 443)) {
      client.print("POST"); 
      client.print(" ");  
      client.print(azureSend);  
      client.println(" HTTP/1.1"); 
      client.print("Host: "); 
      client.println(hostname);  
      client.print("Authorization: ");
      client.println(authSAS);  //authorization SAS token obtained from azure iot device explorer
      client.println("Connection: close");

      client.print("Content-Type: ");
      client.println("application/json");
      client.print("Content-Length: ");
      client.println(content.length());
      client.println();
      client.println(content);
      }
}

Web Application

This is the web application that will run on the cloud, for communicating with the guns and also a UI for owners of the system

Credits

Gideon Hooberman

Gideon Hooberman

1 project • 2 followers

Comments