top of page
tigerzhang513

Connected Device Final Update 2

Updated: Apr 18, 2023

To summarize, this week I spend a lot of time making a little progress.


The Marine Weather API that I chose does have geolocation input (longitude/ latitude). However, the timezone doesn't change accordingly. Therefore I would need to introduce another Time API. The only two data that I need from it is the "timeZone" and "currentLocalTime".


Fortunately, my Marine API can take "TZ Identifier" format data as well as "Time Zone Abbreviation". However, I do realize some "Time zone abbreviation" share the same name, yet totally different time zones. For instance, "China Central Time (CST)" has the exact same abbreviation as North America's "Central Time Zone(CST)". I was very confused but then realized I could just use "TZ identifier" like "America/New_York". OK problem solved!

Coding seemed easy but wasn't at all. The first problem is with Arduino_Json. It cannot convert large Json files (Like in my case I need 9000 bytes from the Marine API). The loop just gets stuck and stops running after a few loops. I know the problem is not the code because it works with Time API, which only needs 1500 bytes. I have no idea how to debug and there wasn't much documentation. Therefore, I decided to switch to another library named ArduinoJson.


Apparently, their developer has some strong feelings against the official Arduino_Json library (LOL). But the library is very well documented and comes with an assistant tool to help you estimate the size of JSON file needed. I managed to get the Marine API to work with 9000 bytes JSON.

Well then, I tried to combine it with the Time API code together. It seems they aren't happy at all. Again, the loop gets stuck. So I switched both of the APIs to be parsed by ArduinoJson instead of Arduino_Json, still, stuck. I realize it probably has to do with my memory. Then I found this "filter" function in the library and decide to give it a try. I do not need the time data from Marine API, only the wave height. The time data was also incredibly space-consuming. By taking it off, I down-scale the JSON to 3500 bytes, which is 3 times smaller than before!

Now everything works like a charm! I'm able to input any geolocation and get its local time as well as wave height in live.


I've been trying to write my code in a way of functions. not sure if it's good practice.


Time API fetch and parse function:


Marine API fetch and parse function:


Parse real current time to int function:


To summarize my code structure:

User Input geolocation

----Time API takes geolocation and returns time zone and real current time

----Marine API takes geolocation and time zone feedback from an array of wave heights based on time. Then I look for the exact data by the real current time.


A screenshot of successful feedback:

Wave height at New York at 18:00 is 0.44 meters!



Question to Tom:

  1. Why does Arduino stuck in the middle of loops? How do I debug?

  2. Is memory monitoring possible? Structure of memories of Arduino?

  3. Is writing everything as a separate function a good practice?

  4. What is this error? I know it's returning String but it won't let me directly assign the value to a global variable.

  5. Multiple return (array return) vs changing global var


6. Arduino stops entering program mode automatically. I have to double tap to reset, why?

7. Could you explain char "*" "&" ? what is a pointer? why does it matter? I've read some online tutorials and failed to understand them thoroughly.







14 views0 comments

Recent Posts

See All

Comments


bottom of page