Ranga Yogeshwar

ISS-Christmas tree:

Ein besonderer Weihnachtsbaum der die aktuelle Position des Weltraumlabors ISS mit seinen Lichtern anzeigt. 

Zum Funktionsprinzip:

Ein Arduino-Mega mit WiFi-Shield ist angeschlossen an eine "intelligente" Lichterkette. Der Arduino läuft als web-client und holt sich regelmässig die aktuellen Positionsdaten der ISS. Diese werden ĂĽber eine api von der NASA bereitgestellt und ständig aktualisiert. Diese Daten werden eingelesen und die aktuellen Werte von Längen- und Breitengrad werden dann auf dem Baum dargestellt. 

Breitengrade(N-S) (=Rot) und Längengrade(W-O)(=Blau) werden nach der jeweiligen Position einer LED zugeordnet. 

HARDWARE:

  • Arduino-Mega 
  • Arduino WiFi-Shield
  • 12mm RGM LED Strang (50) mit WS2801-Treiber
  • Stromversorgung (9V) fĂĽr Arduino
  • Stromversorgung(5V) (ca.2000mA) fĂĽr die LED-Kette

Anbei der CODE:

 

 

WifiWebClientiss7.ino
   1 
   2 
/*
   3 
  ISS-Christmas-tree V.1.0 (R.Yogeshwar, Jan. 2015)
   4 
   5 
This sketch connects to a website api.open-notify.org
   6 
using a WiFi shield and gets the actual position of the ISS. (lat,lon)
   7 
The position is projected on the christmas-tree
   8 
Circuit:
   9 
* WiFi shield attached.
  10 
* Led strip attached with pin2= data Pin(white wire), pin3=clock Pin(green wire), gnd connection.
  11 
* CAUTION: Powersupply for led=5V, arduino = 9V dont mix the power connectors!!!
  12 
Credits: Wifi-part based on dlf (Metodo2 srl) modified 31 May 2012 by Tom Igoe
  13 
Led-strip uses the adafruit library
  14 
*/
  15 
 
  16 
 
  17 
#include <SPI.h>
  18 
#include <WiFi.h>
  19 
#include "Adafruit_WS2801.h" // library for the led strip
  20 
 
  21 
uint8_t dataPin  = 2;    // White wire on Adafruit Pixels
  22 
uint8_t clockPin = 3;    // Green wire on Adafruit Pixels
  23 
Adafruit_WS2801 strip = Adafruit_WS2801(50, dataPin, clockPin);
  24 
char ssid[] = "Wlan_name"; //  your network SSID (name)
  25 
char pass[] = "xxxpasswordxx";    // your network password (use for WPA, or use as key for WEP)
  26 
int keyIndex = 0;            // your network key Index number (needed only for WEP)
  27 
String latitude=""; // first you read a string, then convert it to int, then map it to the led-string
  28 
String longitude="";
  29 
int lat=0;
  30 
int lon=0;
  31 
int ledlat=0; // mapped position on the led-strip
  32 
int ledlon=0;
  33 
int lastlat[4]; // last positions lat
  34 
int lastlon[4]; // last positions lon
  35 
boolean last = false;
  36 
int msgok = -1; // this flag checks if the message was a success
  37 
int status = WL_IDLE_STATUS;
  38 
char server[] = "api.open-notify.org";    // name address  (using DNS)
  39 
WiFiClient client;
  40 
 
  41 
void setup() {
  42 
  //Initialize serial and wait for port to open:
  43 
  Serial.begin(9600);
  44 
 
  45 
  strip.begin();
  46 
  strip.setPixelColor(49, Color(250,0,0)); // Show boot status via red LED
  47 
  strip.show();
  48 
 
  49 
 
  50 
  // check for the presence of the shield:
  51 
  if (WiFi.status() == WL_NO_SHIELD) {
  52 
    Serial.println("WiFi shield not present");
  53 
    // don't continue:
  54 
    while(true);
  55 
  }
  56 
 
  57 
  // attempt to connect to Wifi network:
  58 
  while ( status != WL_CONNECTED) {
  59 
    Serial.print("Attempting to connect to SSID: ");
  60 
    Serial.println(ssid);
  61 
    status = WiFi.begin(ssid, pass);
  62 
    delay(5000);
  63 
  }
  64 
  Serial.println("Connected to wifi");
  65 
  strip.setPixelColor(49, Color(0,250,0));  // show online status via green LED
  66 
  strip.show();
  67 
  printWifiStatus();
  68 
  connectiss(); // connect to server and get data
  69 
}
  70 
 
  71 
void loop() {
  72 
 
  73 
  boolean flag = false;// used for textscraping
  74 
  String currentLine = ""; // contains the JSON part
  75 
  int indexlat=0;
  76 
  int pos1=0;
  77 
  // if there are incoming bytes available
  78 
  // from the server, read them and print them:
  79 
  while (client.available()) {
  80 
    char c = client.read();
  81 
    if (c != '\r'){    // if you got anything else but a carriage return character,
  82 
      if (c == '{') {    // wait until you see the JSON part (we have to do manual text scraping!!)
  83 
        flag = true;
  84 
      }
  85 
      if (flag == true){
  86 
        currentLine += c;  // only fill the interesting part
  87 
      }
  88 
    }
  89 
  }
  90 
 
  91 
  // if the server's disconnected, stop the client:
  92 
  if (!client.connected()) {
  93 
    Serial.println();
  94 
    Serial.println("disconnecting from server.");
  95 
    client.stop();
  96 
    Serial.print(currentLine); // show what you read
  97 
    msgok = currentLine.indexOf("success"); // Check if you really received data (-1) if not 
  98 
    if(msgok>0){
  99 
      indexlat = currentLine.indexOf("latitude"); // get the position of the keyword
 100 
      pos1=indexlat+11;                           // from there get the pos of the numeric value
 101 
      latitude = currentLine.substring(pos1, pos1+10); //read the value of latitude
 102 
      indexlat = currentLine.indexOf("longitude"); // same procedure for longitude
 103 
      pos1=indexlat+11;
 104 
      longitude = currentLine.substring(pos1, pos1+10);
 105 
      lat = latitude.toInt();
 106 
      lon = longitude.toInt();
 107 
      ledlat = map(lat,-90,90,0,49); // map latitude and longitude to the strip
 108 
      ledlon= map(lon,-180,180,0,49);// the last led is used for communication status
 109 
      Serial.println("My data:");
 110 
      Serial.println(lon);
 111 
      Serial.println(lat);
 112 
      Serial.println("Led lat and lon");
 113 
      Serial.println(ledlat);
 114 
      Serial.println(ledlon);
 115 
 
 116 
      lightthem(); // now we can set the lights
 117 
      strip.setPixelColor(49, Color(10,0,10));  // show client off status via pink LED
 118 
      strip.show();
 119 
    }
 120 
    delay(5000);
 121 
    connectiss();
 122 
  }
 123 
}
 124 
 
 125 
 
 126 
// if there is a change, the new position is set and the lights are turned on
 127 
void lightthem(){
 128 
  //First look for a change. If nothing changed, do nothing
 129 
  if(ledlon!=lastlon[3] || ledlat != lastlat[3])
 130 
  { 
 131 
    colorOff(); // All lights off
 132 
   
 133 
    if(ledlon!=lastlon[3]){
 134 
// now shift the positions by 1
 135 
      for(int i=0; i<3;i++){
 136 
        lastlon[i] = lastlon[i+1];
 137 
      }
 138 
      lastlon[3] = ledlon;
 139 
    }
 140 
    if(ledlat != lastlat[3]){
 141 
      for(int i=0; i<3;i++){
 142 
        lastlat[i] = lastlat[i+1];
 143 
      }
 144 
      lastlat[3] = ledlat;
 145 
    }
 146 
   
 147 
    // now turn on the lights as a trail. actual position is most intense
 148 
    strip.setPixelColor(lastlat[3], Color(0,0,250));
 149 
    strip.setPixelColor(lastlat[2], Color(2,0,50));
 150 
    strip.setPixelColor(lastlat[1], Color(4,0,10));
 151 
    strip.setPixelColor(lastlat[0], Color(2,0,2));
 152 
    strip.setPixelColor(lastlon[3], Color(250,0,0));
 153 
    strip.setPixelColor(lastlon[2], Color(50,0,2));
 154 
    strip.setPixelColor(lastlon[1], Color(10,0,4));
 155 
    strip.setPixelColor(lastlon[0], Color(2,0,2));
 156 
    // Mark my home (lat=50,47  LED 38, lon=7,17 LED 25)
 157 
    strip.setPixelColor(38, Color(1,1,2)); // Show home lat
 158 
    strip.setPixelColor(25, Color(2,1,1)); // Show home lon
 159 
    strip.show();
 160 
  }
 161 
}
 162 
 
 163 
// turn off all LEDs
 164 
void colorOff() {
 165 
  int i;
 166 
  for (i=0; i < strip.numPixels(); i++) {
 167 
    strip.setPixelColor(i, 0);
 168 
  }
 169 
  strip.show();
 170 
}
 171 
 
 172 
/* Helper functions */
 173 
// Create a 24 bit color value from R,G,B
 174 
uint32_t Color(byte r, byte g, byte b)
 175 
{
 176 
  uint32_t c;
 177 
  c = r;
 178 
  c <<= 8;
 179 
  c |= g;
 180 
  c <<= 8;
 181 
  c |= b;
 182 
  return c;
 183 
}
 184 
 
 185 
 
 186 
void printWifiStatus() {
 187 
  // print the SSID of the network you're attached to:
 188 
  Serial.print("SSID: ");
 189 
  Serial.println(WiFi.SSID());
 190 
 
 191 
  // print your WiFi shield's IP address:
 192 
  IPAddress ip = WiFi.localIP();
 193 
  Serial.print("IP Address: ");
 194 
  Serial.println(ip);
 195 
 
 196 
  // print the received signal strength:
 197 
  long rssi = WiFi.RSSI();
 198 
  Serial.print("signal strength (RSSI):");
 199 
  Serial.print(rssi);
 200 
  Serial.println(" dBm");
 201 
}
 202 
 
 203 
 
 204 
// Connects to server and makes a GET request
 205 
void connectiss(){
 206 
  Serial.println("\nStarting connection to server...");
 207 
  // if you get a connection, report back via serial:
 208 
  if (client.connect(server, 80)) {
 209 
    strip.setPixelColor(49, Color(0,10,0));  // show online status via green LED
 210 
    strip.show();
 211 
    Serial.println("connected to server");
 212 
    // Make a HTTP request:
 213 
    client.println("GET /iss-now.json HTTP/1.0");
 214 
    client.println("Host: api.open-notify.org");
 215 
    client.println("Connection: close");
 216 
    client.println();
 217 
  }
 218 
}
 219 
 
 220 
 
 221 
 
 222 
 
 223