Google cloud platform 使用ESP-IDF和GoogleCloudPlataform(发布/订阅)实现MQTT
问题已解决 我正在尝试使用ESP-IDF的母语与google iot(发布/订阅)交流我的esp32。我正在使用这个框架。我可以连接到wifi,我可以输入所有必要的信息:项目id,位置id,注册id,设备id,私钥.pem private_key.pem位于目录:Google cloud platform 使用ESP-IDF和GoogleCloudPlataform(发布/订阅)实现MQTT,google-cloud-platform,google-cloud-pubsub,esp32,freertos,Google Cloud Platform,Google Cloud Pubsub,Esp32,Freertos,问题已解决 我正在尝试使用ESP-IDF的母语与google iot(发布/订阅)交流我的esp32。我正在使用这个框架。我可以连接到wifi,我可以输入所有必要的信息:项目id,位置id,注册id,设备id,私钥.pem private_key.pem位于目录:..\examples\smart\u outlet\main\certs,但是我有两个私钥,第一个以----begin----have 2行----end----开头,另一个类似于此格式d4:5z:sq:2A:sg:0s:u8:99:
..\examples\smart\u outlet\main\certs
,但是我有两个私钥,第一个以----begin----have 2行----end----
开头,另一个类似于此格式d4:5z:sq:2A:sg:0s:u8:99:az.
当程序尝试创建JWT时,会显示此错误APP:iotc\u create\u iotcore\u JWT返回错误:71。
我在iotc_error.h库中研究并发现错误71:@cond Numeric code:71*/iotc_JWT_formation_error.
文件iotc_jwt.c:
iotc_state_t iotc_create_iotcore_jwt(
const char* project_id, uint32_t expiration_period_sec,
const iotc_crypto_key_data_t* private_key_data, char* dst_jwt_buf,
size_t dst_jwt_buf_len, size_t* bytes_written) {
if (NULL == project_id || NULL == private_key_data || NULL == dst_jwt_buf ||
NULL == bytes_written) {
return IOTC_INVALID_PARAMETER;
}and the program returns IOTC_INVALID_PARAMETER as an error.
现在在主程序中,我包括iotc_jwt.c,并调用如下所示的证书
extern const uint8_t ec_pv_key_start [] asm ("_ binary_private_key_pem_start");
extern const uint8_t ec_pv_key_end [] asm ("_ binary_private_key_pem_end");
现在我开始定义mqtt参数的任务
static void mqtt_task (void * pvParameters)
{
/ * Format the key type descriptors so that the customer understands
what type of key is being represented. In this case, PEM encoded
byte array of an ES256 key. * /
iotc_crypto_key_data_t iotc_connect_private_key_data;
iotc_connect_private_key_data.crypto_key_signature_algorithm = IOTC_CRYPTO_KEY_SIGNATURE_ALGORITHM_ES256;
iotc_connect_private_key_data.crypto_key_union_type = IOTC_CRYPTO_KEY_UNION_TYPE_PEM;
iotc_connect_private_key_data.crypto_key_union.key_pem.key = (char *) ec_pv_key_start;
最后,创建JWT
/ * Generate the client authentication JWT, which will serve as the MQTT
* password. * /
char jwt [IOTC_JWT_SIZE] = {0};
printf ("creating JWT");
size_t bytes_written = 0;
iotc_state_t state = iotc_create_iotcore_jwt (CONFIG_GIOT_PROJECT_ID,
/ * jwt_expiration_period_sec = * / 3600, & iotc_connect_private_key_data, jwt,
IOTC_JWT_SIZE, & bytes_written);
if (IOTC_STATE_OK! = state) {
ESP_LOGI (TAG, "iotc_create_iotcore_jwt returned with error:% ul", state);
vTaskDelete (NULL);
}
我的问题是:程序代码是否有错误?或者我放错了证书,是否影响了JWT的创建?如果是,证书的正确型号是什么
我认为问题在于从证书到主程序的调用,因为我已经测试了两个证书示例,但之后它就不起作用了
如果有人做了这个交流,你能帮我吗?我相信其他人也有同样的问题
我已经在arduino上进行了通信,通信成功了,我成功地将其发布在IOT核心中,将数据保存在函数中,并实时存储在firebase数据库中。但我需要在IDF-ESPRESSIF上执行此操作
这里解决的问题
问题出在证书中,我正在生成公钥和私钥,但我刚刚收到公钥,因此我在云shell终端中使用了以下命令来解决我的问题 首先,我再次生成私钥:
openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
openssl ecparam-genkey-name prime256v1-noout-out ec_private.pem
然后使用公钥:
openssl ec -in ec_private.pem -pubout -out ec_public.pem
它们是现在创建的,您需要接收它们,这是我的问题,我刚刚用以下命令调用了公钥:cat ec_public.pem
但是我需要的密钥是私有的,所以我使用了这个命令cat ec_private.pem
并收到了密钥,我复制了它并将其粘贴到目录中
...\esp-google-iot\examples\smart_outlet\main\certs\private_key.pem
…\esp谷歌物联网\examples\smart\u outlet\main\certs\private\u key.pem
我这样做了,我的问题就解决了
参考自
谢谢大家!
att,Augusto问题出在证书中,我正在生成公钥和私钥,但我刚刚收到公钥,所以我在cloud shell终端中使用以下命令来解决我的问题 首先,我再次生成私钥:
openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
然后使用公钥:
openssl ec -in ec_private.pem -pubout -out ec_public.pem
它们是现在创建的,您需要接收它们,这是我的问题,我刚刚用以下命令调用了公钥:cat ec_public.pem
但是我需要的密钥是私有的,所以我使用了这个命令cat ec_private.pem
并收到了密钥,我复制了它并将其粘贴到目录中
...\esp-google-iot\examples\smart_outlet\main\certs\private_key.pem
我这样做了,我的问题就解决了
参考自根据,您的问题可能是关键格式。此外,更新问题,将你正在使用的代码用于其他人分析并尝试帮助你。你放的部分太小了。嗨,道尔顿,谢谢你的回复,所以我已经看到了这个链接,用“begin-----end-----”认证的例子测试了它,但它仍然显示错误71,如果有助于更好地理解我的问题,我会用更多行代码编辑出版物。您的
iotc_jwt.c
代码似乎仍然不完整…我的iotc_jwt.c
与此相同,我已经发布了您如何解决问题,因为一旦您获得15点声誉,您将能够。谢谢你的贡献。