1+ #include " Particle.h"
2+
3+ #include " tracker_config.h"
4+ #include " tracker.h"
5+ #include " sht3x-i2c.h"
6+
7+ SYSTEM_THREAD (ENABLED);
8+ SYSTEM_MODE (SEMI_AUTOMATIC);
9+
10+ PRODUCT_ID (TRACKER_PRODUCT_ID);
11+ PRODUCT_VERSION (TRACKER_PRODUCT_VERSION);
12+
13+ SerialLogHandler logHandler (115200 , LOG_LEVEL_TRACE, {
14+ { " app.gps.nmea" , LOG_LEVEL_INFO },
15+ { " app.gps.ubx" , LOG_LEVEL_INFO },
16+ { " ncp.at" , LOG_LEVEL_INFO },
17+ { " net.ppp.client" , LOG_LEVEL_INFO },
18+ });
19+
20+ Sht3xi2c sensor (Wire3, 0x44 );
21+
22+ void locationGenerationCallback (JSONWriter &writer, LocationPoint &point, const void *context); // Forward declaration
23+
24+ void setup ()
25+ {
26+ Tracker::instance ().init ();
27+
28+ // Register a location callback so we can add temperature and humidity information
29+ // to location publishes
30+ Tracker::instance ().location .regLocGenCallback (locationGenerationCallback);
31+
32+ // Turn on 5V output on M8 connector
33+ pinMode (CAN_PWR, OUTPUT);
34+ digitalWrite (CAN_PWR, HIGH);
35+ delay (500 );
36+
37+ sensor.begin (CLOCK_SPEED_400KHZ);
38+ sensor.start_periodic ();
39+
40+ Particle.connect ();
41+ }
42+
43+ void loop ()
44+ {
45+ Tracker::instance ().loop ();
46+ }
47+
48+ void locationGenerationCallback (JSONWriter &writer, LocationPoint &point, const void *context)
49+ {
50+ double temp, humid;
51+
52+ int err = sensor.get_reading (&temp, &humid);
53+ if (err == 0 )
54+ {
55+ writer.name (" sh31_temp" ).value (temp);
56+ writer.name (" sh31_humid" ).value (humid);
57+
58+ Log.info (" temp=%.2lf hum=%.2lf" , temp, humid);
59+ }
60+ else {
61+ Log.info (" no sensor err=%d" , err);
62+ }
63+ }
0 commit comments