diff options
feat: only have exactly 2 response kinds
-rw-r--r-- | api.jsonc | 49 | ||||
-rw-r--r-- | src/bin/server.rs | 120 |
2 files changed, 61 insertions, 108 deletions
diff --git a/api.jsonc b/api.jsonc new file mode 100644 index 0000000..142d8eb --- /dev/null +++ b/api.jsonc @@ -0,0 +1,49 @@ +{ + "api": "0.13", + "api_compatibility": [ + "14", + "15" + ], + "space": "Chaostreff Bern", + "logo": "https://www.chaostreffbern.ch/images/logo_v1.1.png", + "url": "https://www.chaostreffbern.ch", + // TODO: Possibly add location.hint that we are in the basement? + // TODO: Possibly add location.areas for each area in the space? + "location": { + "address": "Zwyssigstrasse 45, 3007 Bern, Switzerland", + "lon": 7.421927, + "lat": 46.944178, + "timezone": "Europe/Zurich", + "country_code": "CH" + }, + "spacefed": { + "spacenet": false, + "spacesaml": false, + "spacephone": false + }, + "state": { + "open": true, + "message": "Open every Tuesday from 19h" + }, + "contact": { + "email": "info@chaostreffbern.ch", + "ml": "bern@chaostreff.ch", + "matrix": "#chaostreffbern:chaostreffbern.ch", + "jabber": "xmpp://chaostreffbern@conference.chaostreffbern.ch", + "mastodon": "@chaostreffbern@chaos.social" + }, + "issue_report_channels": [ + "email" + ], + "feeds": { + "blog": { + "type": "rss", + "url": "https://www.chaosbern.ch/feeds/chaosbern_rss.xml" + }, + "calendar": { + "type": "caldav", + "url": "https://nextcloud.jenix.ch/remote.php/dav/public-calendars/xFMZfKSBNfp3mRNR/" + } + }, + "ext_ccc": "chaostreff" +}
\ No newline at end of file diff --git a/src/bin/server.rs b/src/bin/server.rs index 106295f..a1ac3e2 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -53,7 +53,6 @@ pub enum OurOption<T> { } static BUTTON: Mutex<RefCell<Option<Input>>> = Mutex::new(RefCell::new(None)); -static mut IS_OPEN: bool = false; static mut LED: OurOption<RefCell<Output<'_>>> = OurOption::None; fn set_open_led_state(val: bool) { @@ -169,7 +168,12 @@ fn main() -> ! { loop { match controller.is_connected() { Ok(true) => break, - Ok(false) => {} + Ok(false) => { + set_busy_led_state(true); + delay.delay_millis(10); + set_busy_led_state(false); + delay.delay_millis(500); + } Err(err) => { error!("Failed to connect to wifi: {:?}", err); let mut high = false; @@ -254,120 +258,20 @@ fn main() -> ! { set_busy_led_state(true); if socket.is_connected() { - // debug!("Established Connection"); - - // let mut time_out = false; - // let deadline = time::now() + Duration::millis(500); - // let mut buffer = [0u8; 8192]; - // let mut pos = 0; - // while let Ok(len) = socket.read(&mut buffer[pos..]) { - // if pos + len > buffer.len() { - // error!( - // "We got {} bytes. Buffer overflowed, treating as timeout.", - // pos + len - // ); - // time_out = true; - // break; - // } - - // let to_print = unsafe { core::str::from_utf8_unchecked(&buffer[..(pos + len)]) }; - - // if to_print.contains("\r\n\r\n") { - // break; - // } - - // pos += len; - - // if time::now() > deadline { - // println!("Timeout"); - // time_out = true; - // break; - // } - // } let is_open = button.is_high(); unsafe { set_open_led_state(is_open); } - let parts = [ - // (r##"{ - // "api": "0.13", - // "api_compatibility": [ - // "14", - // "15" - // ], - // "space": "Chaostreff Bern", - // "logo": "https://www.chaostreffbern.ch/images/logo_v1.1.png", - // "url": "https://www.chaostreffbern.ch","##) - // .as_bytes(), - // TODO: Possibly add location.hint that we are in the basement? - // TODO: Possibly add location.areas for each area in the space? - // (r##" - // "location": { - // "address": "Zwyssigstrasse 45, 3007 Bern, Switzerland", - // "lon": 7.421927, - // "lat": 46.944178, - // "timezone": "Europe/Zurich", - // "country_code": "CH" - // }, - // "spacefed": { - // "spacenet": false, - // "spacesaml": false, - // "spacephone": false - // }, - // "state": { - // "open": "##) - // .as_bytes(), - (if is_open { "true" } else { "false" }).as_bytes(), -// r##", -// "message": "Open every Tuesday from 19h" -// }, -// "contact": { -// "email": "info@chaostreffbern.ch", -// "ml": "bern@chaostreff.ch", -// "matrix": "#chaostreffbern:chaostreffbern.ch", -// "jabber": "xmpp://chaostreffbern@conference.chaostreffbern.ch", -// "mastodon": "@chaostreffbern@chaos.social" -// }, -// "issue_report_channels": [ -// "email" -// ], -// "feeds": { -// "blog": { -// "type": "rss", -// "url": "https://www.chaosbern.ch/feeds/chaosbern_rss.xml" -// }, -// "calendar": { -// "type": "caldav", -// "url": "https://nextcloud.jenix.ch/remote.php/dav/public-calendars/xFMZfKSBNfp3mRNR/" -// } -// }, -// "ext_ccc": "chaostreff" -// } -// "## -// .as_bytes(), - ]; - - // if !time_out { - let r =socket - .write_all( - b"HTTP/1.0 200 OK\r\n\ -Content-Type: application/json\r\n\ -UwU: if u read this u have been catgirled :3\r\n\ + + let r = socket.write_all((if is_open { b"HTTP/1.0 200 OK\r\n\ +\r\n\ +1" } else { b"HTTP/1.0 200 OK\r\n\ \r\n\ -", - ); +0" })); if !r.is_ok() { - error!("{:#?}",r.unwrap_err()); + error!("{:#?}", r.unwrap_err()); continue; }; - for part in parts { - let r = socket.write_all(part); - - if !r.is_ok() { - error!("{:#?}", r.unwrap_err()); - continue; - }; - } let r = socket.flush(); if !r.is_ok() { |