58 lines
1.4 KiB
Swift
58 lines
1.4 KiB
Swift
//
|
|
// ArduinoConfig.swift
|
|
// App
|
|
//
|
|
// Created by Marcus Handte on 01.11.22.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
struct ArduinoConfig: Codable {
|
|
var ssid: String
|
|
var password: String
|
|
var token: String
|
|
var id: String
|
|
var latitude: String
|
|
var longitude: String
|
|
|
|
init(ssid: String, password: String, token: String, id: Int64, latitude: Double, longitude: Double) {
|
|
self.ssid = ssid
|
|
self.password = password
|
|
self.token = token
|
|
self.id = "\(id)"
|
|
self.latitude = "\(latitude)"
|
|
self.longitude = "\(longitude)"
|
|
}
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case ssid = "ssid"
|
|
case password = "password"
|
|
case token = "token"
|
|
case id = "id"
|
|
case latitude = "latitude"
|
|
case longitude = "longitude"
|
|
}
|
|
|
|
func toJson() -> Data? {
|
|
let encoder = JSONEncoder()
|
|
let encoded = try? encoder.encode(self)
|
|
if let en = encoded, let string = String(data: en, encoding: .utf8) {
|
|
return "\(string)\n".data(using: .utf8)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
}
|
|
|
|
enum ArduinoConstants: String {
|
|
|
|
/// The network name of the weather station.
|
|
case ssid = "MoWeSta - WiFi"
|
|
/// The network password of the weather station.
|
|
case password = "mowesta123456wifi"
|
|
/// The ip address of the weather station.
|
|
case ip = "192.168.4.1"
|
|
/// The port of the weather station.
|
|
case port = "8080"
|
|
}
|